Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

xhr.open('POST', 'url-here.com'); does not work

POST doesn't work, but GET does. Any idea how to make it work?

— asked May 24th 2010 by Awesome Dude
  • xhr.send
0 Comments

3 Answers

  • A good way to start is posting your code here, may be you are missing the parameters.

    — answered May 24th 2010 by Daniel Lim
    permalink
    0 Comments
  • var xhr = Titanium.Network.createHTTPClient();
    xhr.onerror = xhrOnError;  //xhr_onError function working 
    xhr.onload = function() {
            Ti.API.info(this.responseText);
            Ti.API.info(this.status);
            if(this.status == 200) {
                Ti.API.info('Getting back: ' + this.responseText);
            } else {
                Ti.UI.createAlertDialog({
                    title:'Sorry',
                    message:'Please try again.'
                }).show();
            }
        };
    
      Ti.API.info("sending: " + jsonData);
    
      xhr.open('POST', 'http://someurl.com/index.php'); // index.php is just print_r($_POST) or print_r($_REQUEST)
      xhr.setRequestHeader('Content-Type', 'application/json');
      xhr.setRequestHeader('Accept', 'application/json');
      xhr.send(jsonData);
    
    — answered May 24th 2010 by Awesome Dude
    permalink
    0 Comments
  • The example shown should work fine. Check that you got Internet connectivity..

    — answered May 25th 2010 by Peter Lum
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.