how to console.log result of this ajax call?

Viewed 152812

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

7 Answers

try something like this :

$.ajax({
    type: 'POST',
    url: 'loginCheck',
    data: $(formLogin).serialize(),
    dataType: 'json',
    success: function (textStatus, status) {
        console.log(textStatus);
        console.log(status);
    },
    error: function(xhr, textStatus, error) {
        console.log(xhr.responseText);
        console.log(xhr.statusText);
        console.log(textStatus);
        console.log(error);
    }
});

If you want to check your URL. I suppose you are using Chrome. You can go to chrome console and URL will be displayed under "XHR finished loading:"

Related