how do I assign a variable to a returned response in jQuery
- by netrox
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?