【问题标题】:AJAX not Working in FF, works well in ChromeAJAX 不能在 FF 中运行,但在 Chrome 中运行良好
【发布时间】:2016-04-03 14:10:03
【问题描述】:

我正在将文档上传到服务器,在按钮单击时使用 PHP 和 AJAX 和 JS。我收集表单数据使其对象附加文件数据并通过 AJAX 将其传递给函数 upload.php。该代码在 Chrome 中运行良好,但在 FF 中无法提供相同的效果。代码附在后面。问题的可能解决方案是什么?

$(document).on('click', '#uploadDocument', function()
{
    var formData = new FormData();
    formData.append('fileToUpload', $("#fileToUpload").prop("files")[0]);

    $.ajax({
      url: 'upload.php',
      dataType: 'text',  
      cache: false,
      contentType: false,
      processData: false,
      data: formData,
      type: 'post',
      success: function (status){
        if(status == 'File Uploaded')
        {
          $('#listTable').load('showList.php');
        }
        else
        {}
      }
    });
});

【问题讨论】:

  • 浏览器控制台或php日志中是否有任何错误?
  • @Meiko 没有显示错误,也没有上传文件
  • 请将您的 html 添加到问题中,我看不出 JS 代码有问题。
  • 这可能是由于表单的默认操作,您需要防止这种情况发生。将事件传递给您的 onclick 函数,然后在函数的第一行使用event.preventDefault();
  • @Omarjmh 你的建议成功了 ;)

标签: javascript php ajax google-chrome firefox


【解决方案1】:

这可能是由于表单的默认操作,您需要防止这种情况发生。将事件传递给您的 onclick 函数,然后在函数的第一行使用 event.preventDefault();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2022-07-21
    • 2014-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多