-1

I want to send login data to api of website, if the statusCode returns 302 then I want to redirect the user to another webpage. But my jquery is not executing and giving me the error of $ajax is not defined. Below is my jquery code.

 $("#asd").click(function(){

                alert("sas");
               $ajax({
                            url:'url.com',
                            type: 'POST',

                            data: ({

                                 Username: $('#inputUserName').val(),
                                 password: $('#inputPassword').val(),
                                 returnURL: 'url.com',
                            }),
                            success : function(data, textStatus,jqXHR)
                            {
                                window.location.href="myvideo.html"
                            },
                            error :function(jqXHR, textStatus, errorThrown)
                            {
                                alert("Invalid username and password");
                            }

                     });

                }); 

}); 
Nishit Maheta
  • 5,961
  • 3
  • 15
  • 31
1binary0
  • 93
  • 10

2 Answers2

3

Its $.ajax({}) not $ajax

 $.ajax({
         url:'url.com',
         type: 'POST',
         data: ({
             Username: $('#inputUserName').val(),
             password: $('#inputPassword').val(),
             returnURL: 'url.com',
          }),
          success : function(data, textStatus,jqXHR)
          {
             window.location.href="myvideo.html"
          },
          error :function(jqXHR, textStatus, errorThrown)
          {
             alert("Invalid username and password");
          }
});
Nishit Maheta
  • 5,961
  • 3
  • 15
  • 31
Rohit Arora
  • 2,206
  • 2
  • 23
  • 39
  • Can you tell me how can I get statusCode which is returned by the api? it will return 302 if username and pass is correct, otherwise not. – 1binary0 Apr 07 '15 at 07:26
  • Check this link if you get any help from here : http://stackoverflow.com/questions/5344145/how-to-get-response-status-code-from-jquery-ajax – Rohit Arora Apr 07 '15 at 07:28
0

It is not $ajax but $.ajax

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

You can get more info on this method from link given above

Puneet
  • 2,051
  • 8
  • 17