Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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/85.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 未捕获类型错误:无法设置属性';答复';未定义的_Javascript_Jquery_Http_Xmlhttprequest - Fatal编程技术网

Javascript 未捕获类型错误:无法设置属性';答复';未定义的

Javascript 未捕获类型错误:无法设置属性';答复';未定义的,javascript,jquery,http,xmlhttprequest,Javascript,Jquery,Http,Xmlhttprequest,所以,我有我在2015年写的旧代码,它当时运行良好,但现在它不——有什么问题吗?在使用ajax时,它似乎位于请求函数中,我得到一个错误: VM3641:326 Uncaught TypeError: Cannot set property 'response' of undefined at Object.success (<anonymous>:326:48) at i (jquery.min.js:2) at Object.fireWith [as resolveWith] (j

所以,我有我在2015年写的旧代码,它当时运行良好,但现在它不——有什么问题吗?在使用ajax时,它似乎位于请求函数中,我得到一个错误:

VM3641:326 Uncaught TypeError: Cannot set property 'response' of undefined
at Object.success (<anonymous>:326:48)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4) 

这是因为
this
内部
success
error
回调与它外部的
this
不同。所以
ResponseData
恰好是
未定义的
,因此它不能有
response
属性。尝试使用:


将使回调的作用域设置为您以前的
this
,这是因为
this
内部
成功
错误
回调与外部的
this
不同。所以
ResponseData
恰好是
未定义的
,因此它不能有
response
属性。尝试使用:


将使回调的作用域设置为那些函数中以前的
this

this
成功
错误
)的作用域不会是类的实例,因此
this.ResponseData
在那些函数中是
未定义的
this
success
error
)将不会是您的类的实例,因此
这个。ResponseData
未定义的
。或者只需将
这个
存储在一个变量
中,该变量在外部
并在内部使用。@ibrahimmahrir它也可以工作,但我不建议使用它,因为我发现它不如使用
bind()优雅)
,imo。或者只需将
这个
存储在一个变量
中,该变量在外部
并在内部使用。@ibrahimmahrir它也可以工作,但我不建议这样做,因为我发现使用
bind()
,imo没有这么优雅。
success: function (response) {
    console.log(response);
    this.ResponseData.response = response;
}.bind(this),
error: function (err, errCode, errMessage) {
    this.ResponseData.response = '';
    this.ResponseData.hasErrors = true;
    console.log('error');
}.bind(this)