有没有办法将更多数据传递给jQuery中的回调函数?
我有两个函数,我希望回调$.post,例如,传递AJAX调用的结果数据,以及一些自定义参数
function clicked() {
var myDiv = $("#my-div");
// ERROR: Says data not defined
$.post("someurl.php",someData,doSomething(data, myDiv),"json");
// ERROR: Would pass in myDiv as curData (wrong)
$.post("someurl.php",someData,doSomething(data, myDiv),"json");
}
function doSomething(curData, curDiv) {
}
Run Code Online (Sandbox Code Playgroud)
我希望能够将自己的参数传递给回调,以及从AJAX调用返回的结果.
我有一个ajax调用将数据传递给页面,然后返回一个值.
我已经从页面检索了成功的调用,但我编写了它,以便在asp中引发错误.我如何从jquery中检索该错误?
例如:
cache: false,
url: "addInterview_Code.asp",
type: "POST",
datatype: "text",
data: strData,
success: function (html) {
alert('successful : ' + html);
$("#result").html("Successful");
},
error: function (error) {
**alert('error; ' + eval(error));**
}
Run Code Online (Sandbox Code Playgroud)
这是我不理解的错误位.在函数中我需要放置什么参数,以便我可以使用我在服务器中引发的错误消息.