简体   繁体   中英

jQuery AJAX not working on Firefox

I have a function and an AJAX call. After clicking it gets the function and function works fine, on alert it shows the data, but after that it does not send the data to PHP. Any ideas why this happens on Firefox? It works well in IE and Chrome.

function siparisolustur() {
    var toplamsiparis = $('.urunrow').length;
    var i = null;
    var siparisid = $("#siparis_id").text();

    var name = $("#siparisad").val();
    var surname = $("#siparissoyad").val();
    var tel = $("#siparistel").val();
    var adres = $("#sepetadres").val();
    var semt = $("#sepetilce").val();
    var sehir = $("#sepetsehir").val();
    var notlar = $("#siparisnotu").val();
    var odeme = $('input[name="odemeyontemi"]:checked').attr("id");

    bilgiDataString = '&siparisid=' + siparisid + '&name=' + name + '&surname=' + surname + '&tel=' + tel + '&adres=' + adres + '&semt=' + semt + '&sehir=' + sehir + '&notlar=' + notlar + '&odeme=' + odeme;

    alert(bilgiDataString);

    $.ajax({
        type: "POST",
        url: "https://www.xxxxx.com/procc/xxxxxxxxxx.php",
        data: bilgiDataString,
        cache: false,
        success: function (html) {

        }
    });

    $("#payForm").submit(function (e) {
        var siparisdurdur = 0;
        var ad = $("#siparisad").val();
        var soyad = $("#siparissoyad").val();
        var tel = $("#siparistel").val();
        var adres = $("#sepetadres").val();
        var ilce = $("#sepetilce").val();
        var sehir = $("#sepetsehir").val();
        var sepeturunadetget = parseInt($("#sepeturunsayisi").text());

        if (ad == "" || soyad == "" || tel == "" || adres == "" || ilce == "" || sehir == "" || sepeturunadetget < 1) {
            siparisdurdur = 1;
        }

        if (ad == "") {
            e.preventDefault();
            $("#siparisad").css("border-    color", "#cd2828")
        } else {
            $("#siparisad").css("border-color", "#d1d2e6");
        }
        if (soyad == "") {
            e.preventDefault();
            $("#siparissoyad").css("border-color", "#cd2828")
        } else {
            $("#siparissoyad").css("border-color", "#d1d2e6");
        }
        if (tel == "") {
            e.preventDefault();
            $("#siparistel").css("border-color", "#cd2828")
        } else {
            $("#siparistel").css("border-color", "#d1d2e6");
        }
        if (adres == "") {
            e.preventDefault();
            $("#sepetadres").css("border-color", "#cd2828")
        } else {
            $("#sepetadres").css("border-color", "#d1d2e6");
        }
        if (ilce == "") {
            e.preventDefault();
            $("#sepetilce").css("border-color", "#cd2828")
        } else {
            $("#sepetilce").css("border-color", "#d1d2e6")
        }
        if (sehir == "") {
            e.preventDefault();
            $("#sepetsehir").css("border-color", "#cd2828")
        } else {
            $("#sepetsehir").css("border-color", "#d1d2e6")
        }
        if (blocksubmit == 1) {
            e.preventDefault();
            $("#personalinfosubmit").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
        }
        if (sepeturunadetget < 1) {
            e.preventDefault();
            $("#shoppingcost").css("color", "#cd2828");
            $("#shoppingcost").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
        }

        if (blocksubmit == 0 && siparisdurdur == 0) {
            siparisolustur();
        }
    });

我解决了问题..在ajax完成数据处理之前,提交转到其他页面..我将重定向延迟了大约半秒钟,并且它起作用了。.它与FF的速度有关

I see that you've posted a solution already:

Submit goes to other page before ajax is done proessing the data.. I delayed the redirect for like half second and it worked.

Seriously, you should not be relying on a solution like this.

Timing issues like this are known as a "race condition", ie where two events are effectively in a race to see which one will finish first; you're expecting one to always win, and you get a bug if they finish in the wrong order.

It's a very well defined category of bug (even if Ajax is fairly new, situations like this have existed since the begining of computer science), and the solution is not to slow down one of the events in the hope that you'll force it to always lose. That is always the wrong solution.

The correct solution is usually to trigger the second event only after the first one has finished. In your case, this would mean firing the submit event from inside the ajax success method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM