Jump to content
MakeWebGames

Javascript help


gamble

Recommended Posts

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?

Link to comment
Share on other sites

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

});
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...