suresh gopal
suresh gopal

Reputation: 3156

Page Response Error

I working on iphone Application Development. I created a sampleTest button and whenever i click on it the following function invoking. But unable to return any response. Its showing empty alert message. (hostName and portNo are dynamic inputs)

sampleTestBtn.addEventListener('click', function()
{   
    var regDetails = '{"user_login": {"email": "[email protected]", "password": "password"}}';
    var client = Titanium.Network.createHTTPClient({timeout: 10000});
    client.cache = false;
    client.open("POST", "http://"+hostName+":"+portNo+"/AccountCreate");
    client.setRequestHeader("Content-Type", "application/json");
    client.send(regDetails);    

    alert(JSON.parse(this.responseText));

});

can any one please.

Upvotes: 0

Views: 44

Answers (1)

suresh gopal
suresh gopal

Reputation: 3156

I got the solution.

We need to use onload function. This will get the result from specified url:

My code is below:

var regDetails = '{"user_login": {"email": "[email protected]", "password": "password"}}';
var client = Titanium.Network.createHTTPClient({timeout: 10000});
client.cache = false;
client.open("POST", "http://"+hostName+":"+portNo+"/AccountCreate");
client.setRequestHeader("Content-Type", "application/json");
client.send(regDetails); 

client.onload = function(e)
{
   alert(JSON.parse(this.responseText));
}

Upvotes: 1

Related Questions