jquery ajax Uncaught TypeError :Illegal invocation 报错

Use jquery ajax asynchronous commit time newspaper Uncaught TypeError: Illegal invocation error, error as shown:

 

 

 

 

Basically, this results in the wrong reasons generally have the following two points:

1. incorrect request type, such as, POST request, but is provided in the background get request

2. The parameter is incorrect. For example, the reference did not pass, or the corresponding parameter is not improved

After investigation I broke the second point above, the argument passed is an object, not to a string, the error code is as follows:

    $ (function () { 
            $ ( " #tagging " ) .click (function () {
                 var x.Selector.getSelected MyText = ();
                 var word_id = $ ( ' #word_id ' ) .val ();
                 IF (= MyText = '' ) { 
                    Alert ( " check and then to mark text " ); 
                } 
                the else  IF (word_id <= 0 ) { 
                    Alert ( " operation failed " ); 
                } 
                the else {
                     // var data = {word_id: word_id, mytext: mytext.toString()};
                    var data = {word_id: word_id, mytext: mytext};
                    $.ajax({
                        type: "POST",
                        url: 'ajax.php',
                        data: data,
                        success: function( data, textStatus, jQxhr ){
                            alert(data);
                        },
                        error: function( jqXhr, textStatus, errorThrown ){
                            alert(data);
                        }
                    });
                }
                
            });
        });

 

Use .toString () object to a string, go to the request is successful.

Guess you like

Origin www.cnblogs.com/ryanzheng/p/11839858.html