由于某种原因,这段代码给我抛出了一个未捕获的异常错误。看起来catch块没有捕获该错误。在try catch块中定义的变量作用域是否包括嵌套函数中的错误,以及在上层的catch语句中期望捕获该错误?我在处理的应用程序中去除了一些敏感数据,但预计leadInfo [0 / 1]将是一个32个字符的字母数字字符串,我从URL参数中提取它。
这里的根本问题是我的AJAX调用从API返回一个错误,而该错误在应用程序中未被正确处理。因此需要使用throw语句。AJAX调用正常完成,并返回不包含电子邮件地址属性的JSON对象,因此我需要以某种方式处理它,以更改页面以反映该内容。
这里的根本问题是我的AJAX调用从API返回一个错误,而该错误在应用程序中未被正确处理。因此需要使用throw语句。AJAX调用正常完成,并返回不包含电子邮件地址属性的JSON对象,因此我需要以某种方式处理它,以更改页面以反映该内容。
jQuery(document).ready(function(){
try {
url = "http://api.com/api/v1/lead/" + leadInfo[1]
jQuery.ajax({
type: 'GET',
contentType: 'application/json',
url: url,
dataType : 'jsonp',
success: function (result) {
result = jQuery.parseJSON(result);
if(!result.data.email){
throw ('New exception');
}
console.log(result);
jQuery('.email').html(result.data.email);
}
});
jQuery('.surveryButton').click(function(){
window.location.replace("http://" + pgInventory.host + pgInventory.path + leadInfo[0] + "&curLeadId=" + leadInfo[1] + "&curViewedPages=0");
});
}
catch(err) {
jQuery('.email').html('your e-mail address');
jQuery('#arrowContent').remove();
}
});