admin管理员组文章数量:1026959
I get the following response from the server after doing an ajax request:
{"error":false,"success":true}
My ajax code:
$.ajax({
url: '/update',
type: 'post',
data: $(this).serialize(),
success: function(response) {
alert(response)
},
error: function() {
alert('An error occured, form not submitted.');
}
});
instead of alerting the whole response I want to alert the value of "success", which in this case would be true. How to do this?
I get the following response from the server after doing an ajax request:
{"error":false,"success":true}
My ajax code:
$.ajax({
url: '/update',
type: 'post',
data: $(this).serialize(),
success: function(response) {
alert(response)
},
error: function() {
alert('An error occured, form not submitted.');
}
});
instead of alerting the whole response I want to alert the value of "success", which in this case would be true. How to do this?
Share Improve this question edited Oct 29, 2011 at 2:35 Clive 37k8 gold badges89 silver badges113 bronze badges asked Sep 7, 2011 at 18:04 LindaLinda 1431 gold badge1 silver badge4 bronze badges 1- You have to parse the JSON into a JavaScript object: stackoverflow./questions/4935632/… – Felix Kling Commented Sep 7, 2011 at 18:07
4 Answers
Reset to default 4Like so:
alert(response.success);
$.ajax({
url: '/update',
type: 'post',
dataType: 'json',
data: $(this).serialize(),
success: function(response) {
alert(response.success)
},
error: function() {
alert('An error occured, form not submitted.');
}
});
alert(response.success);
would do it, you can add dataType: 'json'
to your $.ajax options to make absolutely sure it's evaluated as an object in your callback.
Try this:
alert(response.success);
I get the following response from the server after doing an ajax request:
{"error":false,"success":true}
My ajax code:
$.ajax({
url: '/update',
type: 'post',
data: $(this).serialize(),
success: function(response) {
alert(response)
},
error: function() {
alert('An error occured, form not submitted.');
}
});
instead of alerting the whole response I want to alert the value of "success", which in this case would be true. How to do this?
I get the following response from the server after doing an ajax request:
{"error":false,"success":true}
My ajax code:
$.ajax({
url: '/update',
type: 'post',
data: $(this).serialize(),
success: function(response) {
alert(response)
},
error: function() {
alert('An error occured, form not submitted.');
}
});
instead of alerting the whole response I want to alert the value of "success", which in this case would be true. How to do this?
Share Improve this question edited Oct 29, 2011 at 2:35 Clive 37k8 gold badges89 silver badges113 bronze badges asked Sep 7, 2011 at 18:04 LindaLinda 1431 gold badge1 silver badge4 bronze badges 1- You have to parse the JSON into a JavaScript object: stackoverflow./questions/4935632/… – Felix Kling Commented Sep 7, 2011 at 18:07
4 Answers
Reset to default 4Like so:
alert(response.success);
$.ajax({
url: '/update',
type: 'post',
dataType: 'json',
data: $(this).serialize(),
success: function(response) {
alert(response.success)
},
error: function() {
alert('An error occured, form not submitted.');
}
});
alert(response.success);
would do it, you can add dataType: 'json'
to your $.ajax options to make absolutely sure it's evaluated as an object in your callback.
Try this:
alert(response.success);
本文标签: javascriptUsing a JSON responseStack Overflow
版权声明:本文标题:javascript - Using a JSON response - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745652671a2161411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论