使用jQuery 1.8.3时Ajax响应未调用success:function() [英] Ajax response not calling success:function() when using jQuery 1.8.3

查看:415
本文介绍了使用jQuery 1.8.3时Ajax响应未调用success:function()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery 1.8.3时,Ajax响应未调用success:function(),但代码与jQuery 1.4.2完美配合.

Ajax response not calling success:function() when using jQuery 1.8.3 but the code is working perfectly with jQuery 1.4.2.

代码在这里:

<script type="text/javascript">
$(document).ready(function(){
    $("#usn").on('keyup',function() {
        var dat=$("#usn").val();
        if($.trim(dat).length<10){
            $("#result").html("");
            $("#info").show();
        } else if($.trim(dat).length==10) {    
            txt=$("#usn").val();
            txt=txt.toUpperCase();
            var exp = /^[1-9][a-zA-Z][a-zA-Z][0-9][0-9][a-zA-Z][a-zA-Z][0-9][0-9][0-9]$/;
            if(exp.test(txt)){
                var resultType =$("input[name='resultType']:checked").val();
                $("#result").html("<img src=\"./result/loader.gif\"/><br/>Loading...");     
                $.ajax({
                    type: "GET",
                    url: "result/result_html.php?usn="+txt+"&resultType="+resultType,
                    dataType:"JSON",
                    success:function(result){
                        $("#info").hide();
                        $("#result").html(result);              
                        $("#usn").attr("placeholder", "USN"); 
                    }
                });
            } else {
                $("#result").html("Please enter a valid USN.");    
            }
        }
    });
});
</script>

控制台未显示任何错误.我可以在控制台中看到Ajax请求已成功完成.我可以在脚本控制台中看到预期的Ajax响应.

The console is not showing any error. I can see in the console Ajax request is successfully completed. I can see the expected Ajax response in my script console.

可能是什么问题?

推荐答案

在您的$.ajax()调用中,dataType是JSON.您说您的评论中回复为HTML.只需将dataType更改为"html"即可解决此问题.

Within your $.ajax() call, the dataType is JSON. You said the the response was HTML in your comments. Simply changing the dataType to "html" should solve the issue.

这篇关于使用jQuery 1.8.3时Ajax响应未调用success:function()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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