0

我从事 iphone 应用程序开发。我创建了一个 sampleTest 按钮,每当我单击它时,都会调用以下函数。但无法返回任何回应。它显示空警报消息。(hostName 和 portNo 是动态输入)

sampleTestBtn.addEventListener('click', function()
{   
    var regDetails = '{"user_login": {"email": "sample@sample.com", "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.
4

1 回答 1

1

我得到了解决方案。

我们需要使用onload函数。这将从指定的 url 获取结果:

我的代码如下:

var regDetails = '{"user_login": {"email": "sample@sample.com", "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));
}
于 2012-10-31T12:03:23.477 回答