jQuery如何用json建立链接?,错误
我有这个:
$.get('xxx.php', { username: userName },
function(data){
var get_back = data;
alert(get_back);
});
这将返回 get_back=12345
并且我正在尝试构建这个:
url: "http://www.test.com/users/" + get_back,
结果为 http://www.test.com/users/12345
由于某种原因它不想工作。如果我在链接中硬编码 12345
,它将起作用。我还尝试过 url: "http://www.test.com/users/" + get_back + "",
和 url: 'http://www.test.com /users/' + get_back,
有什么想法吗?
编辑:
$.ajax({
type: "POST",
data: JSON.stringify(formData),
dataType: "json",
url: "http://www.test.com/users/" + get_back + "",
success: function(t){ alert(t); }
});
i have this:
$.get('xxx.php', { username: userName },
function(data){
var get_back = data;
alert(get_back);
});
this will return get_back=12345
and i'm trying to build this:
url: "http://www.test.com/users/" + get_back,
the result to be http://www.test.com/users/12345
for some reason it doesn't want to work. If i hard-code the 12345
in the link it will work. i've also tryed url: "http://www.test.com/users/" + get_back + "",
and 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); }
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为
get_back
可能在其他所有内容的范围内。您可以在$.get
调用之前调用get_back
,它将是全局的,或者您可以将其全部放入对象中,如下所示:使用 AJAX 更新
你可能必须以某种方式将
formdata
添加到对象中,我不知道它是在哪里创建的that because
get_back
might be in the scope of everything else. either you can callget_back
before the$.get
call and it will be global or you can put it all into on object like this:UPDATED WITH AJAX
you might have to add
formdata
to the object somehow, i dont know where that was created