Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.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/3/html/69.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_Html_Ajax_Google Chrome - Fatal编程技术网

Javascript 未捕获类型错误:无法读取属性';消息';未定义的

Javascript 未捕获类型错误:无法读取属性';消息';未定义的,javascript,html,ajax,google-chrome,Javascript,Html,Ajax,Google Chrome,我正在尝试为我的站点实现AJAX联系人表单,遇到的问题是,当我单击submit时,在Google Chrome中出现以下错误: "Uncaught TypeError: Cannot read property 'message' of undefined----contact-form.js:38". 请查找并删除 如果查看,您将看到回调函数的第三个参数是包含错误消息的字符串: 错误 Type:Function(jqXHR-jqXHR,String-textStatus,String-err

我正在尝试为我的站点实现AJAX联系人表单,遇到的问题是,当我单击submit时,在Google Chrome中出现以下错误:

"Uncaught TypeError: Cannot read property 'message' of undefined----contact-form.js:38".
请查找并删除

如果查看,您将看到回调函数的第三个参数是包含错误消息的字符串:

错误

Type:Function(jqXHR-jqXHR,String-textStatus,String-errorshown)

请求失败时要调用的函数。这个 函数接收三个参数:jqXHR(在jquery1.4.x中,
XMLHttpRequest
)对象,一个描述错误类型的字符串 如果发生异常,则为可选的异常对象

因此,请尝试以下方法:

error: function(a, b, response) {
     // You can use `a` and `b` if you need them.

     contactForm.addAjaxMessage(response, true);
}

错误是因为
responseJSON
不是a或
XMLHttpRequest
s的一个

你会想,这是:


你应该用JavaScript、Chrome、AJAX等标记它,以便正确的人看到它。在访问它之前检查'response.responseJSON'值,如果它不是空的/未定义的:if(response.responseJSON)。。。。
error: function(a, b, response) {
     // You can use `a` and `b` if you need them.

     contactForm.addAjaxMessage(response, true);
}
contactForm.addAjaxMessage($.parseJSON(response.responseText).message, true);

// or
contactForm.addAjaxMessage(response.responseText, true);