1. ホーム
  2. jquery

Uncaught TypeError。不正な呼び出しの問題を解決しました。

2022-02-07 09:30:25
<パス

まずは具体的な例外メッセージから見ていきましょう。

jquery-1.11.1.min.js:4 Uncaught TypeError: Illegal invocation
    at e (jquery-1.11.1.min.js:4)
    at Vc (jquery-1.11.1.min.js:4)
    at Vc (jquery-1.11.1.min.js:4)
    at Vc (jquery-1.11.1.min.js:4)
    at Vc (jquery-1.11.1.min.js:4)
    at Function.m.param (jquery-1.11.1.min.js:4)
    at Function.ajax (jquery-1.11.1.min.js:4)
    at severCheck (toActiveDuns:302)
    at HTMLInputElement.onblur (VM122 toActiveDuns:99)

再びソースコードを見てみると

function severCheck(){
         if(!checkArea()) return;
        var phone=$('#phone').val();
        var ssuppliercode=$('#ssuppliercode').val();
        var code=$('#code').val(); //identification code
        var name=$('#name').val();
        var password=$('#password').val();
        var randCode=$('#randCode').val(); //page random verification code

    // First step: define json format data
    var postData = {
                "ssuppliercode" : ssuppliercode,
                "code" : code,
                "name" : name,
                "province" : cmbProvince,
                "city" : cmbCity,
                "area" :cmbArea,
                "phone" : phone,
                "password" : password,
                "randCode" : randCode
          };
        //check if the input data meets the specification, and do not go to the next step if it does not

           $.ajax({
            type: "POST",
            url: '<%=basePath%>ytj1001Page/toSendYZM',
            data: postData, //{"phone":phone,"code":randCode}
            dataType:'json', //returned data is json, here to receive with json
            cache: false,
            success: function(data){}
        When debugging, the console reported Uncaught TypeError: Illegal invocation, after checking, it turns out that the ajax request, illegal invocation.

        Specifically, these 3 values were not declared above. 

               "province" : cmbProvince,
               "city" : cmbCity,
               "area" :cmbArea,
When you find the root cause, you understand the reason for the exception: the above exception is reported when a variable is called directly without being declared. So the solution is self-explanatory: just declare the assignment before the call, and be careful to be consistent with the case.


        When debugging, the console reported Uncaught TypeError: Illegal invocation, after checking, it turns out that the ajax request, illegal invocation.

        Specifically, these 3 values were not declared above. 


               "province" : cmbProvince,
               "city" : cmbCity,
               "area" :cmbArea,

When you find the root cause, you understand the reason for the exception: the above exception is reported when a variable is called directly without being declared. So the solution is self-explanatory: just declare the assignment before the call, and be careful to be consistent with the case.