Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jquery ajax成功回调函数中传递上下文_Javascript_Jquery - Fatal编程技术网

Javascript 如何在jquery ajax成功回调函数中传递上下文

Javascript 如何在jquery ajax成功回调函数中传递上下文,javascript,jquery,Javascript,Jquery,我没有在execsuccess方法中获取Box对象。如何在execsuccess方法中传递Box对象?使用,如下所示: var Box = function(){ this.parm = {name:"rajakvk",year:2010}; Box.prototype.jspCall = function() { $.ajax({ type: "post", url: "some url",

我没有在execsuccess方法中获取Box对象。如何在execsuccess方法中传递Box对象?

使用,如下所示:

var Box = function(){
    this.parm = {name:"rajakvk",year:2010};
    Box.prototype.jspCall = function() {
        $.ajax({
            type: "post",
            url: "some url",
            success: this.exeSuccess,
            error: this.exeError,
            complete: this.exeComplete
        });
    }
    this.exeSuccess = function(){
        alert(this.parm.name);
    }
}

context选项决定调用回调的上下文…因此它决定了该函数中该引用的内容。

非常抱歉。目光短浅的jQuery文档。这里提到得很清楚,可能提到得很清楚,但还不清楚如何使用它。尼克的例子很有帮助。这篇文章更为详细:
    $.ajax({
        context: this,
        type: "post",
        url: "some url",
        success: this.exeSuccess,
        error: this.exeError,
        complete: this.exeComplete
    });