Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to console.log result of this ajax call?

Tags:

jquery

ajax

I have the following function in jQuery code:

btnLogin.on('click', function(e,errorMessage){     console.log('my message' + errorMessage);     e.preventDefault();      return $.ajax({         type: 'POST',         url: 'loginCheck',         data: $(formLogin).serialize(),         dataType: 'json'       }).promise();     console.log('my message' + errorMessage); }); 

WHAT I AM TRYING TO DO: I am trying to console.log the error message. I am getting undefined if the console.log line is above the ajax function, and nothing if the console.log is bellow of it.

Can anyone tell me how to get the value of the errorMessage displayed in this or another new function?

Also, any link with about using Ajax for checking php login form will be deeply appreciagted

Regards,Zoran

like image 996
Zoran Avatar asked Aug 19 '12 10:08

Zoran


People also ask

Can I console log in AJAX?

You can also see console. log(response) where success function is written in ajax function. Console. log will print response on browser console.

How do you check if AJAX call is completed?

The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.


1 Answers

Why not handle the error within the call?

i.e.

$.ajax({     type: 'POST',     url: 'loginCheck',     data: $(formLogin).serialize(),     dataType: 'json',     error: function(req, err){ console.log('my message' + err); } }); 
like image 122
Qiau Avatar answered Sep 18 '22 11:09

Qiau