load - jQuery how to build a link with json?, error -
i have this:
$.get('xxx.php', { username: username }, function(data){ var get_back = data; alert(get_back); }); this return get_back=12345
and i'm trying build this:
url: "http://www.test.com/users/" + get_back, the result http://www.test.com/users/12345
for reason doesn't want work. if hard-code 12345 in link work. i've tryed url: "http://www.test.com/users/" + get_back + "", , url: 'http://www.test.com/users/' + get_back,
any ideas?
edit:
$.ajax({ type: "post", data: json.stringify(formdata), datatype: "json", url: "http://www.test.com/users/" + get_back + "", success: function(t){ alert(t); } });
that because get_back might in scope of else. either can call get_back before $.get call , global or can put on object this:
var = { get_back: null, init: function(username){ var self = this; $.get('xxx.php', { username: username }, function(data){ self.get_back = data; self.runajax(); //run ajax when get_back instantiated } }); }, runajax: function(){ var self = this; $.ajax({ type: "post", data: json.stringify(formdata), datatype: "json", url: "http://www.test.com/users/" + self.get_back + "", success: function(t){ alert(t); } }); } } //to use it: get.init(username); //to use get_back alert(get.get_back); updated ajax
you might have add formdata object somehow, dont know created
Comments
Post a Comment