Javascript 未捕获类型错误:无法读取属性';消息';未定义的
我正在尝试为我的站点实现AJAX联系人表单,遇到的问题是,当我单击submit时,在Google Chrome中出现以下错误: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
"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);