• Uncategorized

Adventures in Windows 8: Sending an HTTP POST Request with WinJS.xhr

One of the many things I learned last week was how to use the WinJS.xhr object to send an HTTP POST request to a remote server.

In case you’re wondering, this is how it’s done.

        var targetUri = "http://sampleUri/form.aspx";         var formParams = "sampleField=" + escape(sampleFieldContent);           WinJS.xhr({             type: "post",             url: targetUri,             headers: { "Content-type": "application/x-www-form-urlencoded" },             data: formParams         }).then(function (xhr) {           // This code executes when the xhr response is complete.