I am trying to use an API to retreive some xml data from a server, i need to post three pieces of data to the url. it tried the code below but it ALWAYS gives the error (i.e unsuccesfull), any ideas where im going wrong. im quite new to javascript
?function getinfo()
{
var httpc = new XMLHttpRequest(); // simplified for clarity
var pdata = 'api_key=b9d57f3fbf2faa8d607ad2f46178ab153cc08b45&game_id=k4scvKUW5&response=XML';//i have used wrong values for security
httpc.onreadystatechange = function ()
{
if (httpc.readyState === 4)
{
if (httpc.status === 200)
{
alert(httpc.responseText);
}
else
{
alert('There was a problem with the request!!.');
}
}
};
?httpc.open("POST", "http://www.apisite.com/api/getInfo", true); // sending as POST
httpc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpc.setRequestHeader("Content-Length", pdata.length); // POST request MUST have a Content-Length header (as per HTTP/1.1)
httpc.send(pdata);
};edited><editID>rafhelp</editID><editDate>2012-03-20 04:10:37</editDate></edited>