阿贾克斯成功事件不工作 [英] Ajax success event not working
问题描述
我有一个登记表,现在用 $。阿贾克斯
来提交。
I have a registration form and am using $.ajax
to submit it.
这是我的AJAX请求:
$(document).ready(function() {
$("form#regist").submit(function() {
var str = $("#regist").serialize();
$.ajax({
type: 'POST',
url: 'submit1.php',
data: $("#regist").serialize(),
dataType: 'json',
success: function() {
$("#loading").append("<h2>you are here</h2>");
}
});
return false;
});
});
在我的 submit1.php
文件我检查电子邮件地址
和用户名
存在于数据库中。
我想显示错误消息,如果电子邮件
或用户名
被占用的无需刷新页面。
In my submit1.php
file i check for email address
and username
existence in the database.
I wish to display an error message if the email
or username
are occupied without a page refresh.
我怎样才能把它添加到成功
我的AJAX请求回调?
How can I add this to the success
callback of my AJAX request?
推荐答案
其结果可能不是JSON格式的,所以当jQuery的尝试来分析它是这样,它失败。你能赶上与错误的错误:
回调函数
The result is probably not in JSON format, so when jQuery tries to parse it as such, it fails. You can catch the error with error:
callback function.
您似乎并不需要JSON在功能反正,所以你也可以拿出数据类型:JSON
行
You don't seem to need JSON in that function anyways, so you can also take out the dataType: 'json'
row.
这篇关于阿贾克斯成功事件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!