gamble Posted June 25, 2015 Posted June 25, 2015 I have this: var a = { b: 230000, c: function(){ var b = "derp"; $.get("a.php", function (data, status){ this.b = data; }); return b; } } How do i return the data from the $.get? Ive been working on this and researching for too long now haha. Anyone have any ideas? Quote
Coly010 Posted June 25, 2015 Posted June 25, 2015 Try this: var a = { b: 230000, c: myFunc }; function myFunc(){ var b = "derp"; $.get("a.php", function(data){ return data; } } Done on my phone quickly and untested Quote
Dayo Posted June 25, 2015 Posted June 25, 2015 That is not possible unless you use $.ajax and set async to false (but this would be the wrong way as the rest of the script cant run). To do this properly and asynchronously you would have to do something like this $.get("a.php", function () { var b = "derp"; var a = { b: 2300000, c: data }; // do something with `a` here within the get callback }); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.