Home > DeveloperSection > Forums > jQuery Ajax not work in Safari
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    September-28-2013 4:27 AM

 AJAX AJAX 
Ratings:


 1 Reply(s)
 2272  View(s)
Rate this:
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!



Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    September-28-2013 6:54 AM

Hi Jeet!

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();
            }
        });
    });
});

Don't want to miss updates? Please click the below button!

Follow MindStick