Forme
Forme

Reputation: 301

jQuery Ajax not work in Safari

I have function:

$(function () {
                    $('form').on('submit', function (e) {
                        $.ajax({
                            type: 'POST',
                            url: 'conf/send.php',
                            data: $('form').serialize(),
                            success: function () {
                                var form = document.getElementById("Form");
                                form.submit();
                            }
                        });
                        e.preventDefault();
                    });
               });

In FF, Chrome, Opera, IE work good. In Safari not work. Tried to add:

async: false,

$.ajaxSetup({
  type: 'POST',
  headers: { "cache-control": "no-cache" }
});

$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
   options.data = jQuery.param($.extend(originalOptions.data||{}, { 
     timeStamp: new Date().getTime()
   }));
});

It did not help that could be done? thanks in advance

Upvotes: 0

Views: 3690

Answers (2)

Mark
Mark

Reputation: 1386

Are you sure that this code:

success: function () {
    var form = document.getElementById("Form");
    form.submit();
}

Is actually what you want? You're telling JavaScript that if your form sends via AJAX, it should then send the form with id of #Form. Perhaps you should try this:

$(function() {
    var form = $('form');

    form.on('submit', function(e) {
        e.preventDefault();

        $.ajax({
            type: 'POST',
            url: 'conf/send.php',
            data: form.serialize(),
            success: function (response) {
                console.log(response);
                //var form = document.getElementById("Form");
                //form.submit();
            }
        });
    });
});

Upvotes: 1

Mina
Mina

Reputation: 1516

I think you get stuck in a loop as you form.submit() on success()

Try this

$(function () {
    $('form').on('submit', function (e) {
        $.ajax({
            type: 'POST',
            url: 'conf/send.php',
            data: $('form').serialize(),
        }).done(function(response){ 
            alert(response);
            return true; 
        });
        e.preventDefault();
    });
});

Example here http://fiddle.jshell.net/UKPq5/

Upvotes: 1

Related Questions