4

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.

Vitalii Korsakov
  • 45,737
  • 20
  • 72
  • 90

5 Answers5

13
            $(".readybuy").fadeIn();
            */
        },  < - Extra comma will break IE
    });
}
Daren Schwenke
  • 5,428
  • 3
  • 29
  • 34
5

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.

Jaanus
  • 17,688
  • 15
  • 65
  • 110
3

You need to remove your trailing comma for a start:

   $.ajax({
           ...
        } // No comma here
    });
Greg
  • 316,276
  • 54
  • 369
  • 333
1

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);
    }
});
Josh Mein
  • 28,107
  • 15
  • 76
  • 87
1

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.

Nifle
  • 11,745
  • 10
  • 75
  • 100