jquery ajax在IE中不起作用

时间:2009-10-27 15:22:30

标签: ajax jquery

我有以下功能在我的购物篮中添加文章:

$(".addtocart").click(function(){

   var product = $("#pid").val();
   var qty = $("#qty").val();
   if(isNaN(qty) || qty == '') alert("ERROR");
   else{                                    
        alert("HIHI");

        $.ajax({
            type:"post",
            url:"index.php",
            data:"page=ajax&action=add_product&product=" + product + "&qty=" + qty,
            success: function(html){
                alert("AAA");
                /*
                $("#maininf").html($("#thumbimg").html());
                $("#tinfo").html(html);
                var leftPoint = (Fensterweite()-$(".readybuy").width())/2;
                $(".readybuy").css("left",leftPoint);
                $(".glassbox").fadeIn();
                $(".readybuy").fadeIn();
                */
            },
        });
   }

第一个警报每次都在IE浏览器中。 beforeSend Step也在工作。 但第二个警报永远不会到来。 有谁知道为什么它不适用于IE?

感谢。

5 个答案:

答案 0 :(得分:13)

            $(".readybuy").fadeIn();
            */
        },  < - Extra comma will break IE
    });
}

答案 1 :(得分:5)

http://jslint.com/是确保您的Javascript良好的绝佳工具。解析器错误很常见,我经常也有一个案例,Firefox工作正常,但Safari因为缺少/额外的逗号而在相同的脚本上呕吐。

答案 2 :(得分:3)

您需要删除开头的逗号:

   $.ajax({
           ...
        } // No comma here
    });

答案 3 :(得分:1)

你也可能想在你的ajax调用中添加一个错误部分,以防它出错,因为否则你不会知道

$.ajax({
    type:"post",
    url:"index.php",
    data:"page=ajax&action=add_product&product=" + product + "&qty=" + qty,
    success: function(html){
        alert("AAA");
        /*
        $("#maininf").html($("#thumbimg").html());
        $("#tinfo").html(html);
        var leftPoint = (Fensterweite()-$(".readybuy").width())/2;
        $(".readybuy").css("left",leftPoint);
        $(".glassbox").fadeIn();
        $(".readybuy").fadeIn();
        */
    },
    error: function(error) {
        alert(error);
    }
});

答案 4 :(得分:1)

非常感谢你,但这是另一个错误 请求的php页面需要以下行:

header("Content-Type: text/html; charset=utf-8");

现在一切正常。