JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements

后端 未结 8 1138
醉话见心
醉话见心 2020-11-27 03:38

I have two select elements, A and B: when A\'s selected option changes, B\'s options must be updated accordingly. Each element in A implies many elements in B, it\'s a one-t

相关标签:
8条回答
  • 2020-11-27 03:51

    From the jQuery docs for processData:

    processData Boolean
    Default: true
    By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false.

    Source: http://api.jquery.com/jquery.ajax

    Looks like you are going to have to use processData to send your data to the server, or modify your php script to support querystring encoded parameters.

    0 讨论(0)
  • 2020-11-27 03:51

    I've read in JQuery docs that data can be an array (key value pairs). I get the error if I put:

    This is object not an array:

    var data = {
            'mode': 'filter_city',
            'id_A': e[e.selectedIndex]
    };
    

    You probably want:

    var data = [{
            'mode': 'filter_city',
            'id_A': e[e.selectedIndex]
    }];
    
    0 讨论(0)
  • 2020-11-27 03:58

    Try This:

                $.ajax({
                        url:"",
                        type: "POST",
                        data: new FormData($('#uploadDatabaseForm')[0]),
                        contentType:false,
                        cache: false,
                        processData:false,
                        success:function (msg) {}
                      });
    
    0 讨论(0)
  • 2020-11-27 04:09
    function do_ajax(elem, mydata, filename)
    {
        $.ajax({
            url: filename,
            context: elem,
            data: mydata,
            **contentType: false,
            processData: false**
            datatype: "html",
            success: function (data, textStatus, xhr) {
                elem.innerHTML = data;
            }
        });
    }
    
    0 讨论(0)
  • 2020-11-27 04:12

    I was getting this error while posting a FormData object because I was not setting up the ajax call correctly. Setup below fixed my issue.

    var myformData = new FormData();        
    myformData.append('leadid', $("#leadid").val());
    myformData.append('date', $(this).val());
    myformData.append('time', $(e.target).prev().val());
    
    $.ajax({
        method: 'post',
        processData: false,
        contentType: false,
        cache: false,
        data: myformData,
        enctype: 'multipart/form-data',
        url: 'include/ajax.php',
        success: function (response) {
            $("#subform").html(response).delay(4000).hide(1); 
        }
    });
    
    0 讨论(0)
  • 2020-11-27 04:13
    $.ajax({
                        url:"",
                        type: "POST",
                        data: new FormData($('#uploadDatabaseForm')[0]),
                        contentType:false,
                        cache: false,
                        processData:false,
                        success:function (msg) {}
                      });
    
    0 讨论(0)
提交回复
热议问题