我有这个ajax帖子应该把我带到一个c#mvc controllerMethod:
<script>
$("#save").click(function () {
$.ajax({
url: 'Home/SaveNewPost',
type: 'POST',
data: {
Address1: "423 Judy Road"
},
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data.success);
},
error: function () {
alert("error");
}
});
});
</script>
但是当我用id:#save点击我的div时。我的函数中的错误消息被命中。可能有什么不对?
//由于
答案 0 :(得分:1)
如果设置contentType: 'application/json; charset=utf-8',
试试此代码
$("#save").click(function () {
$.ajax({
url: 'Home/SaveNewPost',
type: 'POST',
data:JSON.stringify({
Address1: "423 Judy Road"
}),
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data.success);
},
error: function () {
alert("error");
}
});
});