473,396 Members | 2,016 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,396 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 6053
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.