Jquery Ajax not working properly in Browser Mobile as well as in MacOS [closed]

1

The following code works perfectly in the Windows 10 Browser, but it does not work in the Android / IOS mobile browser completely, and MacOS gives a message telling the user that it is not working well. The problem seems to be in: success: function(result) .

The rest of the code works, the only thing that does not work is div $ ('# warning'), so I tested it in isolated parts. When run in parts it works, but it's within full code not.

$(function () {

    $("form[name='form-inscricao']").submit(function(e){
        e.preventDefault();

        var $form = $(this);

        var $inputs = $form.find("input, select, button, textarea");

        var serializedData = $form.serialize();

        $inputs.prop("disabled", true);

        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded; charset=UTF-8"
        });

        $.ajax({
            url:'https://www.example.com/wp-content/themes/example.com/enviar.php',
            type: 'post',
            dataType: 'html',
            data: serializedData,
            async: false,
            beforeSend: function(){
                $('.loader').show();
                $('#aviso').text('');
            },
            error: function() {
                console.log('Something went wrong');
            },
            success: function(result){
                $('#aviso').append(result).css({opacity:1.0}).delay(1000).animate({opacity : 0},500);
            },
            complete: function(){
                $('.loader').hide();
                $form.get(0).reset();
                $inputs.prop("disabled", false);

            }});

        });
});
    
asked by anonymous 18.08.2017 / 06:47

1 answer

0

The problem was related to the HTTPS protocol in the URL, for some reason the Mobile Browser is redirected to the http URL without SSL while the browser is not. This way ajax could not return the request to the correct URL. All I did was delete the part of the URL that included http and leave it only from the root folder.

Note: This problem is more likely to occur when using a PHP framework such as WordPress and the links and URLs of the site are not spelled correctly, especially in js scripts like this.

        $.ajax({
            url:'/wp-content/themes/example.com/enviar.php',
    
20.10.2017 / 17:13