我已经定义了JavaScript方法,当我调用该方法时,我得到以下异常
Uncaught ReferenceError: getProvidersList is not defined.
这是我定义的JavaScript方法:
function getProvidersList(categoryIndex){
var index = $('#'+categoryIndex).val();
console.log("index"+index);
var url ='${pageContext.request.contextPath}/rechargewallet/rechargeWalletGetSubCategoryRequest.htm';
$.ajax({
type: "GET",
url: url,
data: "categoryIndex=" + categoryIndex ,
success: function(response){
if('null' != response && (typeof response != 'undefined')){
var subCategoriesList = '<select name=subCategoriesList id=subCategoriesList>';
for (var i = 0; i < response.length; i++) {
var nameOfTheProvider = response[i].nameOfTheProvider;
subCategoriesList = subCategoriesList + '<option value="'+nameOfTheProvider'" label="'+nameOfTheProvider'"></option>';
}
$('#subCategoriesListselectBlock').html(subCategoriesList);
$('#subCategoriesList').show();
}else{
$('#categoriesList').show();
$('#subCategoriesList').hide();
}
}
});
}
这就是我调用上述方法的方法:
<input type="radio" name="categoriesList" id="${categoryName}" value="${category.index}" onclick="getProvidersList(this.id)" />
我在加载页面时也会收到此异常:
uncaught SyntaxError: Unexpected token +
在这一行:subCategoriesList = subCategoriesList + '<option value="'+nameOfTheProvider'" label="'+nameOfTheProvider'"></option>';
我完全感到困惑,通常在没有定义和调用方法时抛出这种异常,但我的情况是,我已经定义了方法并调用了相同的但是为什么我会得到这种undefined
异常?
请告诉我如何解决这个问题..
感谢。
答案 0 :(得分:3)
您在字符串中缺少+
,因为它是语法错误导致整个脚本块无法执行,因此getProvidersList
函数可能无法执行
subCategoriesList = subCategoriesList + '<option value="' + nameOfTheProvider + '" label="' + nameOfTheProvider + '"></option>';