如何console.log此ajax调用的结果? [英] how to console.log result of this ajax call?

查看:161
本文介绍了如何console.log此ajax调用的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jQuery代码中具有以下功能:

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);

   });

我要做什么:我正在尝试console.log错误消息.如果console.log行位于ajax函数上方,则无法定义;如果console.log位于其下方,则不会显示任何内容.

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.

有人可以告诉我如何获取此函数或另一个新函数中显示的errorMessage的值吗?

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

此外,任何有关使用Ajax来检查php登录表单的链接都将得到深深的赞赏

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

问候,佐兰

推荐答案

为什么不处理调用中的错误?

Why not handle the error within the call?

$.ajax({
    type: 'POST',
    url: 'loginCheck',
    data: $(formLogin).serialize(),
    dataType: 'json',
    error: function(req, err){ console.log('my message' + err); }
});

这篇关于如何console.log此ajax调用的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆