jquery - Change value on success, but not changing -
this question has reply here:
how homecoming response asynchronous call? 11 answersi need alter var state on success, debugging js code, doesn't phone call success function @ all, though there success. state variable remains undefined. i'm not sure why doesn't change. looking @ network using firebug, response {"d": 1}, value state should have. help appreciated
var state; $.ajax({ url: "isoserve.asmx/getstatus", type: "get", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (msg) { state = msg.d; }, error: function() { alert("error" ); } }); homecoming state;
you should return state within ajax call:
var state;
$.ajax({ url: "isoserve.asmx/getstatus", type: "get", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (msg) { state = msg.d; homecoming state; }, error: function() { alert("error" ); } }); in case, return statement fires before ajax response come! says, asynchronous, need wait till gets response.
you cannot have response ajax phone call directly, asynchronous request. instead, can invoke function in success callback, such function triggered , states set.
jquery ajax json
No comments:
Post a Comment