2011-01-25 25 views
0

的AJAX POST得不到P​​OST參數的代碼如下:爲什麼jQuery中

$.ajax({ 
    type: "POST", 
    url: "http://localhost:3000/rcm/global_config/update",  
    data: {k: 'sdfa', v: 'dsfas'}, 
    success: function(data, textStatus, XMLHttpRequest){ 
     alert("數據更新成功"); 
    }, 
    error: function(xhr,textStatus, errorThrown){ 
     alert("數據更新失敗,請刷新回滾"); 
    } 
    }); 

在服務器我不能得到後的參數,然後我篡改阿賈克斯發送的請求時,它不完全發送數據參數。我不知道我錯在哪裏。

謝謝你提前。

+0

你可以得到的參數,如果你通過GET給他們而不是POST? – regality 2011-01-25 04:16:57

+0

更改爲獲得,一切正常。 – ywenbo 2011-01-25 04:19:29

+0

我正在嘗試使用http://jqueryconsole.com/及其結果很好的方式來調試您的代碼。在網絡面板中使用chrome開發人員工具我收到了帶有正確表單數據k:sdfa和v:dsfas的表單發佈請求。也許這是一個瀏覽器問題。嘗試使用其他瀏覽器。 – Gajahlemu 2011-01-25 04:22:05

回答

0

嘗試

$.ajax({ 
type: "POST", 
url: "http://localhost:3000/rcm/global_config/update",  
data: "{'k': 'sdfa', 'v': 'dsfas'}",  // Change are here in this line 
success: function(data, textStatus, XMLHttpRequest){ 
    alert("數據更新成功"); 
}, 
error: function(xhr,textStatus, errorThrown){ 
    alert("數據更新失敗,請刷新回滾"); 
} 
}); 
0
$.ajax({ 
    type: "POST", 
    url: "http://localhost:3000/rcm/global_config/update",  
    data: $.param({k: 'sdfa', v: 'dsfas'}), 
    success: function(data, textStatus, XMLHttpRequest){ 
     alert("數據更新成功"); 
    }, 
    error: function(xhr,textStatus, errorThrown){ 
     alert("數據更新失敗,請刷新回滾"); 
    } 
    }); 

結束語在$ .PARAM數據對象應該這樣做。這將是對象轉換爲字符串「K = sdfa & V = dsfas」

0

喜 請嘗試財產以後這樣的:

$.ajax({ 
     type:"POST", 
     url:"student/info/ajax.php", 
     data:({type:'test', r:which}), 
     success:function(data){ 
      if((data.result)=='true') 
       $('#result_popup').html(data.output); 
      }, 
     dataType:"json"}); 
     return false;