I am trying to POST a raw string via jQuery.ajax()
e.g.,
contact_list=352345
I have
$.ajax({
beforeSend: function(xhr){
xhr.setRequestHeader('Content-Type', header);
}
},
url: link,
type: type,
processData:false,
data: data,
success: function(data){
console.log(data);
}
});
Most of the time I am sending JSON data, so header='application/json'
On the server side, I echo $HTTP_RAW_POST_DATA and see my JSON string just fine.
However, I sometimes want to send normal form data too. But when I set header='application/x-www-form-urlencoded' $HTTP_RAW_POST_DATA is empty.
ProcessData is false, so shouldn’t it just pass my string on through?
As a temporary workaround I’m just leaving the header as application/json and ignoring the Content-Type on the server for this particular endpoint.
PHP
$HTTP_RAW_POST_DATAis not available with enctype=”multipart/form-data”. http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-dataSo, now on the server I do the following:
Seems to be working.