Is there a way to return a value (xml in my case) from a JQuery Ajax Call -
I think I'm missing something very original and maybe someone can fill me in. I have used an AJAX call from two places. So now I'm trying to reuse the call with a return value. It looks like this:
function getInfo () {$ .ajax ({type: "GET", url: "..//// Jax.aspx? Action = getInfo & id = 4 ", datatype:" xml ", async: false, error: work () {warning (" something went wrong. ");}, Success: function (xml) {// some extra work here $ (xml) "Cell"). Each (function () something based on {// XML}}; // something else you can use this XML, so return it back as well. // why does not it work ??? Return xml;}}); }
Somewhere else in the script I am calling that function
var xml = getInfo (); // Try to do something with it but it says that it is undefined
and when I say it is undefined, I'm talking about firebug. Stop the asynchronous functionality IMHO is not a very good AJAX programming style, you will relax several benefits of this technique.
. From the Jquery documentation:
Note that synchronous requests can temporarily lock the browser, when the request is active.
Anyway if you need to: $ .jax makes XMLHTTPRequest object that creates it and your getInfo method should also be returned in that form too, so your code should Should be modified:
function getInfo () {return $ .ajax ({type: "GET", url: "./ajax.aspx?action=getInfo&id=4" , Data type: "xml", async: false, error: work () {warning ("something went wrong.");}, Success: function (xml) {// some extra work here $ (XML) Funds ("Cells"). Each (function () {// do something based on XML}}; // Some can use this XML so that it also return it back. / / Why does not it work? Return xml;}}) Reaction text; } Var xml = getInfo ();
Comments
Post a Comment