所以我试图实现以下,但我无法弄清楚如何使这项工作。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