【问题标题】:AJAX passing data string and image file to phpAJAX 将数据字符串和图像文件传递给 php
【发布时间】:2016-05-07 07:31:03
【问题描述】:

是否可以在一个函数中使用 dataString 传递图像文件?

我有这样的东西:

 $.ajax({
        type: "POST",
        url: "../insert.php",
        data:  dataString, 
        success: function(response){
             console.log(response);
        }
      });

一切正常。除了图像不发送到 php,只有名称 - 这很明显。但是如何实现呢?

【问题讨论】:

标签: php jquery ajax file


【解决方案1】:

查看此链接:How to send image to PHP file using Ajax?

接受的答案应该发送所有输入(字符串和文件)。

要添加额外的输入,您可以尝试:

var extraInput = document.createElement('input');
extraInput.type = 'text';
extraInput.name = 'name';
extraInput.value = '...';

formData.appendChild(extraInput);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-10
  • 2013-06-29
  • 1970-01-01
  • 2011-02-12
  • 2019-06-18
  • 2014-08-18
相关资源
最近更新 更多