jQuery AJAX POST variables not accessible on server
I am using jQuery to post some data to an asp.net mvc site. The post takes place successfully and the target controller action is hit when I debug it in Visual Studio, however it seems that the data I am passing is not getting carried over. I can't see it either in Request.Params or Request.Headers My post is a开发者_运维知识库s follows:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
headers: {signature: authHeader},
type: "POST",
// tried this data: authHeader
success: function() { alert('Success!'); }
});
Am I missing something here ?
you need to post your data in the data
property:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: {signature: authHeader},
type: "POST",
// tried this data: authHeader
success: function() { alert('Success!'); }
});
headers
isn't a valid option for $.ajax()
, you want data
instead, like this:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: {signature: authHeader},
type: "POST",
success: function() { alert('Success!'); }
});
If you do want to set headers, you should do it in the beforeSend
event handler, like this:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
beforeSend: function(xhr) {
xhr.setRequestHeader("signature", authHeader);
},
type: "POST",
success: function() { alert('Success!'); }
});
精彩评论