JQuery ajaxForm: форма не отправляется, если она удалена из DOM в beforeSubmit - PullRequest
0 голосов
/ 15 мая 2011

Если я удаляю форму из DOM в beforeSubmit или beforeSend (не имеет значения, какой именно), я нахожу, что и в IE, и в FF http-запрос никогда не отправляется.вызывается строка 296 form.submit () в jquery.form.js, но http-запрос не отправляется.Тем не менее, он работает корректно в Chrome.

Пример кода:

$('#form1').ajaxForm(
    {
        beforeSubmit: function(array, matched_set, options)
        {
            // this line removes #form1 from the DOM.
            // it is still available to jquery form plugin by means of closure
            // line 296 form.submit() in jquery.form.js is hit,
            // but IE and FF never emit http request. If I remove this line, it works.
            $('#jqm_window').html(waiting_page);
        },

chrome: enter image description here firefox: enter image description here Трассировка http сохраняется в fiddler при использовании chrome (но не в других браузерах): enter image description here

Ответы [ 2 ]

1 голос
/ 18 мая 2011

это не проблема jquery.IE, FF не отправляют форму, если она удалена из DOM перед отправкой.Полный код:

<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.1.min.js">
</script>
<script>
$(document).ready(function()
{
    $('#test').click(function(e)
    {
        e.preventDefault();
        var form = $('#uploadForm')[0];
        // IE and FF will not submit the form if its removed from the DOM
        // Chrome doesn't care. you will get 404 error, as it submits the form to non-existent files.php
        form.parentNode.removeChild(form);
        form.submit();
    });
});
</script>
</head>
<body>
<form id="uploadForm" action="files.php" method="POST" enctype="multipart/form-data">
    File: <input type="file" name="file" />                
    <input type="submit" value="Submit" />
</form>
<a href="#" id="test">Click to test</a>
</body>
</html>
0 голосов
/ 10 сентября 2013

У меня та же проблема.Я создаю объект формы jQuery и вызываю функцию отправки, которая прекрасно работает в Chrome, но не в Firefox.

В Chrome и Firefox используются разные движки js, а в Firefox вы не можете отправить элемент формы, отсутствующий в DOM.

...