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
You can also see console. log(response) where success function is written in ajax function. Console. log will print response on browser console.
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.
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); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With