weixin_33670713 2018-06-13 08:59 采纳率: 0%
浏览 82

数据未定义

Console states the following errors when I hit the submit button on my page:

process.js:19 Uncaught ReferenceError: data is not defined
at HTMLButtonElement.<anonymous> (process.js:19)
at HTMLButtonElement.dispatch (jquery-3.3.1.min.js:2)
at HTMLButtonElement.y.handle (jquery-3.3.1.min.js:2)

This is my jQuery AJAX code that executes when you hit the submit button. This is my first time playing with AJAX/jQuery - not sure what is happening so if someone could help me, that'd be greatly appreciated!

$(document).ready(function() {
$('#login_button').click(function()
{
    event.preventDefault();
    var formData = {
        'email'         : $('input[email=email').val(),
        'password'      : $('input[password=password').val()
    };

    $.ajax({
        type        : 'POST',
        url         : 'ajax/proclogin.php',
        data        : formData,
        dataType    : 'json'
    });

    // using the done promise callback

        if (data.success == false)
        {
            if(data.errors.email)
            {
                //toastr.error(''+data.errors.email+'', 'Oops!');
                alert('Email error');
            }
            else if(data.errors.password)
            {
                //toastr.error(''+data.errors.password+'', 'Oops!');
                alert('Password Error');
            }
        }
        else
        {
            //toastr.success('Works!', 'WooHoo!');
            alert('Works.');
        }
});
});
  • 写回答

5条回答 默认 最新

  • ?Briella 2018-06-13 09:05
    关注

    The response or data is available in the success callback of $.ajax call.

     $.ajax({
            type        : 'POST',
            url         : 'ajax/proclogin.php',
            data        : formData,
            dataType    : 'json'
        }).done(resp => {
           // You IF statements go here.
        }).fail(error => {
    
        });
    

    Look at the docs at: jQuery

    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存