how do I assign a variable to a returned response in jQuery
Posted
by netrox
on Stack Overflow
See other posts from Stack Overflow
or by netrox
Published on 2010-03-29T22:40:34Z
Indexed on
2010/03/29
22:43 UTC
Read the original article
Hit count: 304
I wanted to assign a returned value (just text) to a variable in jQuery. I wrote this:
var hm=22;
$.ajax({
type: "GET",
url: "ajax_check_match.php",
dataType: "text",
success:callback
});
function callback(data, status)
{
// assign ajaxed value to cm variable
cm=data;
if (hm != cm)
{
dosomething();
}
}
But it fails every time. Why is that the cm variable keeps getting undefined when it sends request. I set the php file to return 1 and it still says undefined. I opened ajax_check_match.php in browser and I see "1".
I didn't see the point of using XML or JSON since a simple number would suffice. Or do I have to use XML/JSON?
© Stack Overflow or respective owner