相关疑难解决方法(0)

在Safari 10.13.4中发送包含空文件输入的FormData()时,AJAX请求失败

我正在运行一个基于Symfony 2.8的Web应用程序,它使用Ajax将一些表单数据发送回控制器.

到目前为止一切工作正常,但自从最新的macOS更新到版本10.13.4用户开始报告,提交表单在Safari中不再起作用.10.13.4上的其他macOS版本和其他浏览器仍然可以正常工作,因此它似乎是Safari中的一个问题.当然我向Apple提交了一份错误报告,但我不认为,我会从那里得到反馈......

我能够找出问题的根源:提交包含空文件输入的数据失败:

// safri_bug.html
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head>
<body>
    <form name="app_booking" method="post" action="/test/submit.php">
        <div><input type="text" id="someValue" name="value"></div>
        <div><input id="thefile" type="file" name="file"></div>
    </form>

    <button id="bSubmit" type="button">Submit</button>

    <script>    
        $(document).ready(function() {              
            $('#bSubmit').click(function() {
                var form = $('form');
                var data = new FormData(form[0]);

                $.ajax({
                    url : '/submit.php',
                    type : 'POST',
                    data : data,
                    contentType: false,
                    processData: false,
                    context : this,
                    success : function(response) {
                            alert('success: ' + response);
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                            alert('error: ' + xhr.responseText + ' …
Run Code Online (Sandbox Code Playgroud)

javascript safari ajax macos jquery

14
推荐指数
3
解决办法
4816
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

macos ×1

safari ×1