Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

jQuery AJAX success doesn't work in Firefox

I have this little AJAX call:

    $('#brick-mixer-form').submit(function(e) { 
        e.preventDefault();

        $("#mix-bricks-submit").addClass("load");
        $("#mix-bricks-submit").attr("value", "Blander sten..");

        var form_data = $("#brick-mixer-form").serialize()

        $.ajax({
           type: "GET",
           url: "build.php",
           data: form_data,
           dataType: 'text',
           async: false,
           success: function(data) {
              $(".active").attr('src', 'build.php?'+form_data+'').load(function() {
              $("#mix-bricks-submit").removeClass("load");
              $("#mix-bricks-submit").attr("value", "Bland igen");
              $("#bricks-selected").attr("value", form_data);
              $("#pdf_saver").css("display", "block");
           });
        }
     });
});

In Google Chrome this works perfect, but in Firefox I can only trigger it once.

When I press the submit button "mix-bricks-submit" again it will not run the call a second time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to .load() the url parameter is not optional so either

$('#brick-mixer-form').submit(function(e) { 
        e.preventDefault();

        $("#mix-bricks-submit").addClass("load");
        $("#mix-bricks-submit").attr("value", "Blander sten..");

        var form_data = $("#brick-mixer-form").serialize()

        $.ajax({
           type: "GET",
           url: "build.php",
           data: form_data,
           dataType: 'text',
           async: false, //I would avoid forcing synchronous
           success: function(data) {
              //$(".active").attr('src', 'build.php?'+form_data+'').load(function() {
              $("#mix-bricks-submit").removeClass("load");
              $("#mix-bricks-submit").attr("value", "Bland igen");
              $("#bricks-selected").attr("value", form_data);
              $("#pdf_saver").css("display", "block");
           //});
           }
        });
});

or

$('#brick-mixer-form').submit(function(e) { 
        e.preventDefault();

        $("#mix-bricks-submit").addClass("load");
        $("#mix-bricks-submit").attr("value", "Blander sten..");

        var form_data = $("#brick-mixer-form").serialize()

        $.ajax({
           type: "GET",
           url: "build.php",
           data: form_data,
           dataType: 'text',
           async: false,//I would avoid forcing synchronous
           success: function(data) {
              $(".active").load('build.php',form_data,function() {
                $("#mix-bricks-submit").removeClass("load");
                $("#mix-bricks-submit").attr("value", "Bland igen");
                $("#bricks-selected").attr("value", form_data);
                $("#pdf_saver").css("display", "block");
              });
           }
        });
});

Although why would execute the ajax statement twice i am unsure of


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...