所以我試圖實現以下,但我無法弄清楚如何使這項工作。jQuery ajax請求:如何在成功函數中訪問發送的數據?
$.ajax({
url: "whatever.php",
method: "POST",
data: { myVar: "hello" },
success: function(response) {
console.log('received this response: '+response);
console.log('the value of myVar was: '+data.myVar); // <<<< data.myVar is not accessible from here
console.log('the value of myVar was: '+myVar); // <<<< myVar is not accessible from here
}
});
是否有訪問的.success()
功能的myVar
值的方法嗎? 我可以以某種方式獲取原始的data
對象,該對象是在這個ajax請求中發送的,在.success()
函數中?
希望得到您的解決方案。 謝謝!
你測試只是console.log(myVar)? –
@Gabriel Rodrigues是的,我做了,但沒有奏效...... – Xriter
沒有辦法從成功處理程序中訪問'$ .ajax()'的參數。您當然可以將該參數分配給更高範圍的變量,然後傳遞該變量。然後,你將能夠從'success'處理程序中訪問該變量。 – jfriend00