R
R
romaaa322020-04-26 23:29:18
JavaScript
romaaa32, 2020-04-26 23:29:18

Why doesn't preventDefault() work in Safari?

Hello! The code below works in Chome, Yandex Browser, but not in Safari.

$('#form_setting').click(function(e) {
        var data = $('#player_setting');
        $.ajax({
            type: data.attr('method'),
            url: data.attr('action'),
            data: data.serialize(),
            success:function(data) {
            }
        });
    })


And like this, it e.preventDefault();works in Safari, but I need the action to be performed, i.e. as in above code withoute.preventDefault();

$('#form_setting').click(function(e) {
        e.preventDefault();
        var data = $('#player_setting');
        $.ajax({
            type: data.attr('method'),
            url: data.attr('action'),
            data: data.serialize(),
            success:function(data) {
            }
        });
    })


By clicking on the only button on the page, 2 form data is sent to different pages (at the moment, only such a solution appears in my head), but Safari sends ajax only if the default button action is stopped (return false/preventDefault), but it should after sending ajax - the second form is sent and the page is updated.
I don't know JavaScript, please help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romaaa32, 2020-04-27
@romaaa32

$('#form_setting').click(function(e){
        var data = $('#player_setting');
        $.ajax({
            type: data.attr('method'),
            url: data.attr('action'),
            data: data.serialize(),
            success:function(data) {
                $('#setting').submit();
            }
        })
    })

Removed form binding from buttonform="form_setting"
<button type="submit" name="submit" id="form_setting">Сохранить</button>

Added a hidden field to determine if the form has been submitted in PHP
<input type="hidden" name="form_setting" value="1">

G
Gregory, 2020-04-27
@Loovery

Try to submit form yourself after ajax submit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question