views:

28

answers:

2

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 as 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 ?

+4  A: 

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!'); }
});
Jason
Hi Jason, I tried the following:- $.ajax({ url: "http://localhost/PlatformPortal/Buyers/Account/SignIn", data: { signature: authHeader }, type: "POST", success: function() { alert('Success!' + authHeader); } }); Still nothing on the server side. Is there something specific I should be looking at in the Request type ? I check Request.Params
Cranialsurge
if you have firebug, when the post happens, check the "Post" tab to see what you sent to the server. it may be a binding issue with MVC where you're not correctly specifying what to bind.
Jason
+1  A: 

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!'); }
});
Nick Craver