使用javascript发送formdata,并使用php接收

使用javascript发送formdata,并使用php接收,javascript,php,ajax,content-disposition,Javascript,Php,Ajax,Content Disposition,如何从PHP的内容处置中访问元素?这里,formdata是通过javascript发送的。如果内容类型未设置为form urlencoded,它将返回空字符串 var fdata = new FormData(); fdata.append('id',id); fdata.append('img',nwImg); fdata.append('hdng',hdng); fdata.append('cntnt',cntnt); var xmlHttp = new XMLHttpRequest();

如何从PHP的内容处置中访问元素?这里,formdata是通过javascript发送的。如果内容类型未设置为form urlencoded,它将返回空字符串

var fdata = new FormData();
fdata.append('id',id);
fdata.append('img',nwImg);
fdata.append('hdng',hdng);
fdata.append('cntnt',cntnt);

var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function(xhr){
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
    {
        alert(xmlHttp.responseText);
    }
}
xmlHttp.open("post", "http://localhost/dashcntrl/file/upld"); 
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(fdata);
但在JavaScript中分配setRequestHeader时会附加内容处置。它将在返回时返回
print\r($\u POST)


如何在不进行内容处理的情况下访问名称和值

删除
xmlHttp.setRequestHeader(“内容类型”、“应用程序/x-www-form-urlencoded”)顺便说一下,您还可以使用
xhr.onload=function(){}
,这样您就不必测试
xhr.status==200&&xhr.readyState==4
。只发送一个comment.does图像,而不发送
xmlHttp.setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”)
您是否在
上获得该图像,如
const fd=new FormData;document.getElementById('whatever').onchange=function(event){const files=event.files;if(files.length){const file=files[0];fd.append('imagefilesuperglobalname',file);}
?还要记住异步行为。
Array
(
[-----------------------------18619978915867
Content-Disposition:_form-data;_name] => "id"

-----------------------------18619978915867
Content-Disposition: form-data; name="img"


-----------------------------18619978915867
Content-Disposition: form-data; name="hdng"

5
-----------------------------18619978915867
Content-Disposition: form-data; name="cntnt"

)