Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

javascript - Ajax成功事件不起作用(Ajax success event not working)

I have a registration form and am using $.ajax to submit it.(我有一个注册表,正在使用$.ajax提交。)

This is my AJAX request:(这是我的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; }); }); In my submit1.php file I check for the existence of fields email address and username in the database.(在我的Submit1.php文件中,我检查数据库中是否存在电子邮件地址用户 名字段。) I wish to display an error message if those value exist without a page refresh .(如果这些值存在而没有页面刷新,则希望显示一条错误消息。) How can I add this to the success callback of my AJAX request?(如何将其添加到我的AJAX请求的成功回调中?)   ask by noobcode translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The result is probably not in JSON format, so when jQuery tries to parse it as such, it fails.(结果可能不是JSON格式,因此当jQuery尝试如此解析时,它将失败。)

You can catch the error with error: callback function.(您可以使用error: callback函数来捕获错误。) You don't seem to need JSON in that function anyways, so you can also take out the dataType: 'json' row.(无论如何,您似乎都不需要在该函数中使用JSON,因此您也可以取出dataType: 'json'行。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...