Skip to main content
added 2 characters in body
Source Link
php_nub_qq
  • 16.1k
  • 25
  • 84
  • 150

I'm trying to send a multipart/form-data content-type request:

var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState==4){ alert(xhr.responseText); } } xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type","multipart/form-data; boundary=---------------------------275932272513031"); xhr.send('-----------------------------275932272513031 Content-Disposition: form-data; name="name" test ----------------------------275932272513031'275932272513031--'); 

Then in php I just print the $_POST array

print_r($_POST); 

But I get an empty array each time. I expect to see

Array ( name => "test" ) 

What am I doing wrong?

I'm trying to send a multipart/form-data content-type request:

var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState==4){ alert(xhr.responseText); } } xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type","multipart/form-data; boundary=---------------------------275932272513031"); xhr.send('-----------------------------275932272513031 Content-Disposition: form-data; name="name" test ----------------------------275932272513031'); 

Then in php I just print the $_POST array

print_r($_POST); 

But I get an empty array each time. I expect to see

Array ( name => "test" ) 

What am I doing wrong?

I'm trying to send a multipart/form-data content-type request:

var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState==4){ alert(xhr.responseText); } } xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type","multipart/form-data; boundary=---------------------------275932272513031"); xhr.send('-----------------------------275932272513031 Content-Disposition: form-data; name="name" test ----------------------------275932272513031--'); 

Then in php I just print the $_POST array

print_r($_POST); 

But I get an empty array each time. I expect to see

Array ( name => "test" ) 

What am I doing wrong?

Source Link
php_nub_qq
  • 16.1k
  • 25
  • 84
  • 150

Javascript XHR send multipart/form-data

I'm trying to send a multipart/form-data content-type request:

var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState==4){ alert(xhr.responseText); } } xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type","multipart/form-data; boundary=---------------------------275932272513031"); xhr.send('-----------------------------275932272513031 Content-Disposition: form-data; name="name" test ----------------------------275932272513031'); 

Then in php I just print the $_POST array

print_r($_POST); 

But I get an empty array each time. I expect to see

Array ( name => "test" ) 

What am I doing wrong?