このjavacsript関数があり、正常に動作していますが、コードを追加しましたが、そのコードをコメントアウトしない限り、エラーが発生します:
ReferenceError: updateListingForm is not defined
完全なコードは次のとおりです。
function updateListingForm(type) {
if (jQuery('#voucher_value').length){
var voucher_value = jQuery('#voucher_value').val();
} else {
var voucher_value = null;
}
if (jQuery('#category_id')val().length > 0 && isNaN(jQuery('#category_id').val()) == false) {
var category_id = jQuery('#category_id').val();
} else {
var category_id = 0;
}
var loadUrl = relative_path + 'ajax_files/change_listing_type.php';
var dataObject = { type: type, category_id: category_id, voucher: voucher_value }
getAjaxData(loadUrl, dataObject, 'GET', 'json')
.done(function(response) {
console.log(response);
// Add/remove the listing field stuff
jQuery('#listing_type').html(response.listing_type);
// Input addl cat fee
jQuery('#addl_cat_fee').html(response.addl_cat_fee);
})
.fail(function() {
alert('There seems to have been a problem changing the listing type; please contact us if this continues to occur.');
});
// End
}
以下のコードをコメントアウトすると、正常に動作します。
if (jQuery('#category_id')val().length > 0 && isNaN(jQuery('#category_id').val()) == false) {
var category_id = jQuery('#category_id').val();
} else {
var category_id = 0;
}
ただし、正常に動作させるには、上記をコメントアウトする場合、明らかに次の行を追加する必要があります。
var category_id = 0;
このエラーが発生するコードの何が問題になっていますか?