Javascript 使用JS和PHP从表单上载文件时出现Post错误

Javascript 使用JS和PHP从表单上载文件时出现Post错误,javascript,php,Javascript,Php,我想用JS和PHP从表单上传文件。但当我发送文件时,我收到了POST错误 我的表单(HTML): <input type="file" class="custom-file-input" id="file" multiple name="file" onchange="readURL()"/> function readURL() { var file

我想用JS和PHP从表单上传文件。但当我发送文件时,我收到了POST错误

我的表单(HTML):

    <input type="file" class="custom-file-input" id="file" multiple name="file" 
          onchange="readURL()"/>
function readURL() {
 var files = document.getElementById("file").files;

 if (files.length > 0) {
  var formData = new FormData();
  formData.append("file", files[0]);
  var xhttp = new XMLHttpRequest();
  xhttp.open("POST", "send.php", true);

  xhttp.onreadystatechange = function () {
   if (this.readyState == 4 && this.status == 200) {
    var response = this.responseText;
    if (response == 1) {
     console.log("Upload successfully.");
    }else{
     console.log("File not uploaded.");
    }
   }
 };

 xhttp.send(formData);
 }else{
 console.log("Please select a file");
 }
}
send.php文件(php)

在控制台中,我收到错误:

    <input type="file" class="custom-file-input" id="file" multiple name="file" 
          onchange="readURL()"/>
function readURL() {
 var files = document.getElementById("file").files;

 if (files.length > 0) {
  var formData = new FormData();
  formData.append("file", files[0]);
  var xhttp = new XMLHttpRequest();
  xhttp.open("POST", "send.php", true);

  xhttp.onreadystatechange = function () {
   if (this.readyState == 4 && this.status == 200) {
    var response = this.responseText;
    if (response == 1) {
     console.log("Upload successfully.");
    }else{
     console.log("File not uploaded.");
    }
   }
 };

 xhttp.send(formData);
 }else{
 console.log("Please select a file");
 }
}


p.S.File send.php位于主目录中,路径正常

我找到了一个解决方案,对于要提供的静态文件,我必须配置中间件以将静态文件添加到管道中

Startup.cs

public void Configure(IApplicationBuilder app)
{
 app.UseStaticFiles();
}

有关此问题的更多信息,请参见

404=>未找到页面。您的php文件是否位于项目的根目录下?我看到端口44355,您的本地项目是否在localhost:44355上运行良好?我们可以看到您的树文件吗?(它是ASP.NET核心项目),是的PHP文件位于我的项目的根目录中