Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

javascript - $.post throwing "Illegal invocation "

Edit: None of the answers suggested so far have worked at all.

I'm running this call with django. The first time it runs, the server returns "n_usr" (which changes the form the user files in). The second time, it just throws an Illegal invocation error.

function log_in () {

        username = $('#usr_enter').val();
        password = $('#pass_enter').val();
        if(!n_usr){
            $.post('/ajax/login',{password: password, username: username}, function(data) {
              if(data == "n_usr"){
                $('#new_user_entry').show('slow');
                n_usr = true;
              }
              else {

              }

            })
    }else {
        password2 = $('#pass_re_enter');
        penname = $('#pen_enter');
            $.post('/ajax/login', {password: password, password2: password2, username: username, pen_name: penname, TN: "TN"}, function(data) {
                if(data == "e_act"){

                } else {

                }
            });
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your else, you have:

password2 = $('#pass_re_enter');
penname = $('#pen_enter');

Then you have:

{password: password, password2: password2, username: username, pen_name: penname, TN: "TN"}

You are getting Illegal invocation because jQuery is trying to serialize the jQuery object for $.post, and it can't. It's probably trying to call a string method, and is passing it a jQuery object as context, thus causing the error.

You need to add .val().

password2 = $('#pass_re_enter').val();
penname = $('#pen_enter').val();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...