javascript - What/when does a call to the jQuery AJAX method return? -
a little background:
i trying implement , ajax powered slickgrid. there isn't documentation used this example base.
in example there following code hits desired web service data:
req = $.jsonp({ url: url, callbackparameter: "callback", cache: true, // digg doesn't accept autogenerated cachebuster param success: onsuccess, error: function(){ onerror(frompage, topage) } }); req.frompage = frompage; req.topage = topage;
i'm not sure jsonp does i've read appears similar ajax method in jquery except returns json , allows cross domain requests. webservice happen calling returns xml changed chunk of code to:
req = $.ajax({ url: "/_vti_bin/lists.asmx", type: "post", datatype: "xml", data: xmldata, complete: onsuccess, error: function (xhr, ajaxoptions, thrownerror) { alert("error: " + xhr.statustext); alert(thrownerror); }, contenttype: "text/xml; charset=\"utf-8\"" }); req.frompage = frompage; req.topage = topage;
my issue page errors out @ req.frompage = frompage;
because req
null.
am wrong think can replace jsonp call call ajax method? req not set because ajax call hasn't finished time code executed? how can around either of these issues?
if comment out last 2 lines , hard-code values elsewhere runs fine.
am wrong think can replace jsonp call call ajax method?
no, should work fine.
is req not set because ajax call hasn't finished time code executed?
yes, correct.
the ajax methods starts request , returns immediately. if want after response has arrived should in success
event handler.
you might want use success
event instead of complete
event, complete
event happens if there error.
you could specify async: false,
in settings make ajax call wait response, means browser freezes while it's waiting.
Comments
Post a Comment