19

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 {

                }
            });
        }
    }
Olli
  • 1,231
  • 15
  • 31
sinθ
  • 11,093
  • 25
  • 85
  • 121

2 Answers2

21

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();
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • What I was going to suggest as well. – Burhan Khalid Jul 31 '12 at 13:41
  • I love you. I had a similar error and for some reason I forgot to add a parameter with ".val()", I was getting the most weird errors. After an hour, I made it right! I always do the most little errors..it takes a lot of attention. Tjìhank you ;) – G4bri3l Mar 17 '14 at 16:40
0

Well you are not calling them the same -- the first time:

 $.post(url_base+'/ajax/login' ...

and the 2nd

  $.post('/ajax/login', {....

Change the 2nd one to include url_base.

Hogan
  • 69,564
  • 10
  • 76
  • 117
  • url_base is an empty string that I thought I had removed from the program. Adding it to the 2nd call does not change anything. Thanks though. – sinθ Jul 30 '12 at 21:15