xmlhttprequestwinjs

Posting JSON object through WinJS.XHR


I'm having abit of problems posting data from WinJS.xhr to a PHP script. "obj" is a stringified JSON object

WinJS.xhr({
            type: "POST",
            url: dataUrl,
            headers: { "Content-type": "application/x-www-form-urlencoded" },
            data: obj,
        })

However the $_POST variable is always empty.

I've tried changing content-types, and escaping the object but no luck :(


Solution

  • Figured out a soloution.

    Incase anyone has the same problem i got it working by removing headers from the xhr, and getting the post data @ server side with this code:

    $data = file_get_contents('php://input');
    $data = (array) json_decode($data);