1

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;
    }
});
14
  • Have you tried enabling PHP error reporting? Commented Nov 9, 2017 at 17:30
  • I think I have. But could you please tell me how to verify! Commented Nov 9, 2017 at 17:31
  • stackoverflow.com/questions/1053424/… Commented Nov 9, 2017 at 17:32
  • Yes, I have then! Nothings shows! Commented Nov 9, 2017 at 17:32
  • What does echo file_get_contents('php://input') give you? Maybe the string is just not parseable as you expect? Commented Nov 9, 2017 at 17:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.