类型错误:'null'不是对象(正在评估'响应.productType')

TypeError: 'null' is not an object (evaluating 'response.productType')

本文关键字:评估 响应 productType 错误 null 类型 对象      更新时间:2023-09-26

嘿,伙计们,我对Ajax有点陌生,但我的代码出现了这个错误:TypeError:'null'不是对象(正在计算'response.productType'),我不知道为什么。这是代码,提前谢谢。所有这些都包含在文档中。准备

function handleLupGoBrowseResponse(response){
    if(response.productType == "MSG"){
        if(LOCALE == 'en_US'){
            $('p.success').html(lupSuccessEn);
            $(lupUpsellEn).insertAfter('.headerTopBar');
            //alert("yes"); remove for prod
        }else if(LOCALE == 'fr_CA'){
            $('p.success').html(lupSuccessFr);
            $(lupUpsellFr).insertAfter('.headerTopBar');
        }else if(LOCALE == 'ja_JP'){
            $('p.success').html(lupSuccessJp);
            $(lupUpsellJp).insertAfter('.headerTopBar');
        }
    }else{
        //alert("no"); remove for prod
        //alert(lupMobile); remove for prod
    }
}

if(lupAjaxUrl != ""){
    $.ajax({
        url: lupAjaxUrl,
        cache: false,
        pageCache: false,
        dataType: "jsonp",
        success: handleLupGoBrowseResponse
    });
}

ajax调用的响应不是对象,它被评估为null。在函数的开头添加一个条件来测试这个值

function handleLupGoBrowseResponse(response){
    if(response) {
        // execute your code
    } else {
        console.log(response);
    }
}