2010-07-15 24 views
0

我正在使用jQuery将一些数据发布到asp.net mvc网站。在Visual Studio中调试它时,该帖子发生成功,并且目标控制器操作被击中,但似乎我传递的数据没有得到结转。我看不出它无论是在Request.Params或Request.Headers我的职位是如下:jQuery AJAX服务器上无法访问的POST变量

$.ajax({ 
     url: "http://localhost/PlatformPortal/Buyers/Account/SignIn", 
     headers: {signature: authHeader}, 
     type: "POST", 
     // tried this data: authHeader 
     success: function() { alert('Success!'); } 
    }); 

我在这里失去了一些东西?

+0

什么是'authHeader'? – 2010-07-15 00:24:23

回答

4

你需要在data属性来发表您的数据:

$.ajax({ 
    url: "http://localhost/PlatformPortal/Buyers/Account/SignIn", 
    data: {signature: authHeader}, 
    type: "POST", 
    // tried this data: authHeader 
    success: function() { alert('Success!'); } 
}); 
+0

您好杰森,我尝试以下内容: - $ .ajax({url:“http:// localhost/PlatformPortal/Buyers/Account/SignIn”, data:{signature:authHeader}, type:“POST” , 成功:function(){alert('Success!'+ authHeader);} });仍然在服务器端没有。请问在Request类型中应该注意什么?我检查Request.Params – Cranialsurge 2010-07-15 00:49:58

+0

如果你有萤火虫,当这个帖子发生时,检查“发布”标签,看看你发送给服务器。它可能是MVC的一个绑定问题,您无法正确指定要绑定的内容。 – Jason 2010-07-15 16:25:36

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