Post data to url using httprequest

0 favourites
  • 2 posts
From the Asset Store
We present to you “Post Apocalyptic Trailer” – our newest hard hitting, bass rumbling designed movie trailer collection.
  • 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>

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I am not skilled enough yet to help you on your script, but why don't you just use the Plugin that is already available?

    scirra.com/forum/plugin-ajaxpost_topic49039.html

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)