JQUERY AJAX NOT WORK IN SAFARI

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
AJAX 
 3008  View(s)
Ratings:
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!

  1. Ankita Pandey

    Post:183

    Points:1285
    Re: jQuery Ajax not work in Safari

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!