473,224 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Hello World with YUI Library - asyncRequest

Hi, here I have a very simple 'hello world' example that makes use of
Yahoo! User Interface Library. I have a problem with my response string
coming back as '[object, Object]'. I managed to check that everything
else works.

The requested 'SayHello.html' file only contains the string "hello,
world".

Here is my code:

<html>
<head>
<title>Hello World with YUI</title>
<script src="yahoo.js"></script>
<script src="connection.js"></script>
<script language="JavaScript" type="text/javascript">
var handleSuccess = function(o){
if(o.responseText !== undefined){
document.getElementById('span_result').innerHTML = o.responseText;
}
}

var handleFailure = function(o){
document.getElementById('span_result').innerHTML = 'ERROR: ' +
o.responseText;
}

var callback =
{
success:handleSuccess,
failure: handleFailure
};
</script>
</head>
<body>
<!-- Clicking this link initiates the asyncronous request -->
<a href="javascript:YAHOO.util.Connect.asyncRequest(' GET',
'SayHello.html', callback);">Say Hello</a><br>
<!-- used to display the results of the asyncronous request -->
<span id="span_result"></span>
</body>
</html>

Aug 9 '06 #1
3 6039
Hi again, I found what was wrong with my test page.

At the bottom of the page where I have the Anchor link I had this:

<a href="javascript:YAHOO.util.Connect.asyncRequest(' GET',
'SayHello.html', callback);">Say Hello</a><br>

I replaced it with this:

<a href="#" onclick="javascript:YAHOO.util.Connect.asyncReques t('GET',
'SayHello.html', callback);">Say Hello</a><br>

This prevents the browser from navigating away from the page and
instead you just handle the 'onclick' event.

Cheers,
SV.

Aug 10 '06 #2
sa********@gmail.com wrote:
Hi again, I found what was wrong with my test page.

At the bottom of the page where I have the Anchor link I had this:

<a href="javascript:YAHOO.util.Connect.asyncRequest(' GET',
'SayHello.html', callback);">Say Hello</a><br>

I replaced it with this:

<a href="#" onclick="javascript:YAHOO.util.Connect.asyncReques t('GET',
'SayHello.html', callback);">Say Hello</a><br>

This prevents the browser from navigating away from the page and
instead you just handle the 'onclick' event.
The browser will still "browse" to #.
It's even better when you replace it with this:

<a href="#" onclick="YAHOO.util.Connect.asyncRequest('GET',
'SayHello.html', callback); return false;">Say Hello</a><br>

or

<a href="noscript.html" onclick="YAHOO.util.Connect.asyncRequest('GET',
'SayHello.html', callback); return false;">Say Hello</a><br>
Aug 11 '06 #3
Robert wrote:
sa********@gmail.com wrote:
<snip>
><a href="#"
onclick="javascript:YAHOO.util.Connect.asyncReque st('GET',
'SayHello.html', callback);">Say Hello</a><br>

This prevents the browser from navigating away from the page and
instead you just handle the 'onclick' event.

The browser will still "browse" to #.
It's even better when you replace it with this:
I suspect that "handle the 'onclick' event" could mean; call -
preventDefault - and/or setting - returnValue - on the event object, so
returning false would only be necessary for back-compatibility (even if
the back-compatible method is reliable on all modern browsers).
<a href="#" onclick="YAHOO.util.Connect.asyncRequest('GET',
'SayHello.html', callback); return false;">Say Hello</a><br>

or

<a href="noscript.html"
onclick="YAHOO.util.Connect.asyncRequest('GET', 'SayHello.html',
callback); return false;">Say Hello</a><br>
The problem with that, and certainly the latter, is that if the method
calls fails, or cannot act (such as when IE 5-6 is set up with ActiveX
disabled in the Internet security zone and the page is on the Internet),
the onclick event is still cancelled. An alternative noscirpt.html page
may be a sensible response to failure due to the browser not supporting
scripting, but there should be an equally sensible response to the
browser not supporting the action attempted by the script (and they will
likely be the same response (so long as the former is not haranguing the
user for not having javascript available)).

The only code that is in a position to asses the viability of the
actions it is attempting would be the function/method called from the
onclick handler (or the handler itself) so the optimum pattern should
be - onclick="return doSomethingFun('parameter');" - and have the
function/method return true or false to signal its success.

Of course general purpose libraries don't know how they are going to be
used and so will not tend to be designed with such methods signalling
their success in such a way, or designed with any consideration of clean
degradation at all.

Richard.

Aug 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Andy Sutorius | last post by:
Has anyone successfully created a Hello World program without using Visual Studio.NET? If so, what IDE did you use and what namespaces did you import? Thanks! Andy Sutorius
17
by: Tim Judd | last post by:
I must not be grasping anything here. Just a simple application, as follows (as any first-program is...) ---- #include <iostream.h> int main() { cout <<"hello world"; return 0;
9
by: PG | last post by:
Hi gurus, I have AIX visual age C++ compiler version 5.0.2.3. I have a simple hello world program that gives compilation errors. Any help will be appreciated. Thanks PG ***test.cpp**** ...
6
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
33
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use...
26
by: Santanu Chatterjee | last post by:
Hello all, I would like to know how an OS makes a computer boot up. For that, as a start I would like to see an e_ample (read the underscore as the letter before y, as the keyboard here is...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
1
by: petermichaux | last post by:
Hi, I have a general JavaScript library API design question based on some examples I have seen. There seem to be two options The first option is used by the AJAX libraries and by Matt Kruse's...
1
by: James T. Dennis | last post by:
You'd think that using things like gettext would be easy. Superficially it seems well documented in the Library Reference(*). However, it can be surprisingly difficult to get the external details...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.