I am trying to make a PUT request with the following, and it works just fine on localhost but it show empty once I try to run it on my domain. I have checked that PHP versions are the same on both localhost and shared server. I checked the and made sure that allow_url_fopen=On
. Basically this is the part that does not work. I am trying to get the body of the PUT request from the 'php://input' with the following parse_str(file_get_contents('php://input'), $_PUT);
and it returns empty. Moreover when I check to see if the file exists file_exists('php://input')
, it says the file does not exists.
I read that these are called wrappers. I have tried reading from different variables and files but it still does not work.
/**************** EDIT ***************/
var ajax = function(object){
var oo, xhr;
oo = j2.extend({
method: 'get',
credentials: false,
beforesend: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}, object);
if("XMLHttpRequest" in window){
xhr = new XMLHttpRequest();
}
else{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.onreadystatechange = function(e){
if(xhr.readyState === 4){
oo.complete && oo.complete(xhr);
if(xhr.status >= 200 && xhr.status < 300){
oo.success && oo.success(xhr);
}
else if(xhr.status >= 400 && xhr.status < 600){
oo.error && oo.error(xhr);
}
}
else if((xhr.readyState === 3) && (oo.loading)){
oo.loading(xhr);
}
else if((xhr.readyState === 2) && (oo.headers)){
oo.headers(xhr)
}
else if((xhr.readyState === 1) && (oo.received)){
oo.received(xhr);
}
}
xhr.open(oo.method, oo.action, true);
xhr.withCredentials = oo.credentials;
j2.foreach(oo.beforesend, function(v, k){
xhr.setRequestHeader(k, v);
});
xhr.send(oo.data);
};
ajax({ method: 'put', action: 'the url to send the request'
, data: _.data(form) /* function that url encodes the inputs in the form*/
, received: function(){
form.update.disabled = true;
}
, success: function(xhr){
_.process(xhr);
}
, error: function(xhr){
_.process(xhr);
}
, complete: function(){
form.update.disabled = true;
}
});