2010-07-15 54 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!'); } 
});