我正在使用jQuery将一些数据发布到asp.net mvc网站。当我在Visual Studio中调试它时,帖子成功发生并且目标控制器操作被命中,但是我传递的数据似乎没有被转移。我无法在Request.Params或Request.Headers中看到它我的帖子如下:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
headers: {signature: authHeader},
type: "POST",
// tried this data: authHeader
success: function() { alert('Success!'); }
});
我在这里错过了什么吗?
答案 0 :(得分:4)
您需要在data
属性中发布您的数据:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: {signature: authHeader},
type: "POST",
// tried this data: authHeader
success: function() { alert('Success!'); }
});
答案 1 :(得分:2)
headers
不是$.ajax()
的有效选项,您需要data
,如下所示:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: {signature: authHeader},
type: "POST",
success: function() { alert('Success!'); }
});
如果你做想要设置标题,你应该在beforeSend
事件处理程序中执行此操作,如下所示:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
beforeSend: function(xhr) {
xhr.setRequestHeader("signature", authHeader);
},
type: "POST",
success: function() { alert('Success!'); }
});