【发布时间】:2016-08-08 16:43:59
【问题描述】:
我在 ajax 中遇到了问题。场景是:我想验证用户在输入电子邮件时是否可用。所以我在 javascript 中创建了一个函数来使用其中的 Ajax 脚本来执行此操作。 这是我的代码:
$('#username').keyup(function () {
var email = $(this).val();
$.ajax({
type: 'GET',
url: 'http://localhost:8080/MeublesTunisv4/web/app_dev.php/email-verification/' + email,
dataType: "json",
beforeSend: function () {
$('#email_status').html('<img id="loading" src ="{{ asset('bundles/theme_front_end/images/loading.gif')}}"></img>');
},
success: function (data) {
$('#email_status').remove();
$('#email_status').html('<img id="loading" src ="{{ asset('bundles/theme_front_end/images/green_tick.png')}}"></img>');
}
});
});
我的问题是:当我输入任何单词时,它会调用 keyup 函数,即使数据为空,它也会成功。我想让它只有在数据正确完成的情况下才能成功。 谢谢。
【问题讨论】:
标签: javascript ajax