JQUERY、AJAX请求然后循环数据
有人看到以下内容有什么问题吗:
$.ajax({
url: '/tags/ajax/post-tag/',
data: { newtaginput : $('#tag-input').val(), customerid : $('#customerid').val()},
success: function(data) {
// After posting
alert(data);
arr = data.tagsinserted.split(',');
alert(arr);
//Loop through
$.each(arr, function(n, val){
alert(n + ' ' + val)
});
}
}, "json");
tagsinserted 是返回的内容,这是完整的回复:
{"returnmessage":"The Ajax operation was successful.","tagsinserted":"b7,b4,dog,cat","returncode":"0"}
谢谢
Does anyone see anything wrong with the following:
$.ajax({
url: '/tags/ajax/post-tag/',
data: { newtaginput : $('#tag-input').val(), customerid : $('#customerid').val()},
success: function(data) {
// After posting
alert(data);
arr = data.tagsinserted.split(',');
alert(arr);
//Loop through
$.each(arr, function(n, val){
alert(n + ' ' + val)
});
}
}, "json");
tagsinserted is what's being returned, here is the full response:
{"returnmessage":"The Ajax operation was successful.","tagsinserted":"b7,b4,dog,cat","returncode":"0"}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Anurag 在他的评论中是正确的 json need to be
dataType:'json'
也,除非指定,请求默认为“GET”,您的网址表明它正在等待发布数据,即
type: '发布'
Anurag is right in his comment json needs to be
dataType:'json'
also, unless specified, request is "GET" by default, your url suggests it is expecting post data, i.e.
type:'post'