开发者

jquery ajax doesn't work in IE

i have the following function to add an article in my basket:

$(".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();
                */
            },
        });
   }

the first alert is alling everytime in IE. the开发者_开发问答 beforeSend Step is working too. But the second alert is never coming. Has anybody an idea why it doesn't work on IE?

Thanks.


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


http://jslint.com/ is a great tool to make sure your Javascript is good. Parser errors are common, I have often also had a case where Firefox works fine but Safari pukes on the same script because of missing/extra commas.


You need to remove your trailing comma for a start:

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


you also may want to add an error part to your ajax call just in case it errors out because otherwise you wont know

$.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);
    }
});


Thank you very much but it was another error.
The requested php Page needs the following line:

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

And now everything works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜