{ "id": "110927", "key": "AC-1979", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "5", "description": "All attempts at reproducing this issue failed, or not enough information was available to reproduce the issue. Reading the code produces no clues as to why this behavior would occur. If more information appears later, please reopen the issue.", "name": "Cannot Reproduce" }, "resolutiondate": "2013-03-14T16:47:03.000+0000", "created": "2013-03-11T02:33:42.000+0000", "labels": [ "android" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:40:55.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14550", "name": "Appcelerator Modules", "description": "Please enter tickets related to Modules here." }, { "id": "14545", "name": "Documentation" }, { "id": "14551", "name": "Studio", "description": "Please enter tickets related to Titanium Studio here." }, { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "please, I have problems using the callback function when I'm waiting data from a webservice, I need to split the code to stay in separate classes or applying a standard structure commonjs, this is my code but i cant catch whats wrong, i cant see my alerts messages.\r\n\r\n\r\nFile: MisWebServices.js\r\n\r\n{code}\r\nexports.consumirWS = function(callback) {\t\r\n var client = Ti.Network.createHTTPClient({\r\n onload : function(e) { \r\n if (callback) { \r\n callback(this.responseText);//I also did the test here with this.responseXML\r\n }\r\n },\r\n\r\n // function called when an error occurs, including a timeout\r\n onerror : function(e) {\r\n Ti.API.debug(e.error);\r\n alert('error');\r\n },\r\n timeout : 5000 // in milliseconds\r\n });\r\n\r\n client.open(\"GET\", \"http://www.miurl.com\");\r\n client.send();\r\n}\r\n{code}\r\n\r\n\r\n\r\nNow, my file app.js\r\n\r\n{code}\r\nWS = require('/MisWebServices');\r\n\r\nfunction callback(datos){\r\n try { \r\n alert('b'+JSON.stringify(datos)); // Displays information in text format\r\n\r\n //If I use the JSON.parse also not work\r\n //var datosJSON = JSON.parse(datos); \r\n\r\n var items = datos.documentElement.getElementsByTagName(\"element\");\r\n var arrData = [];\t\r\n\r\n for (var i=0; i < items.length; i++) {\r\n arrData.push({\r\n Country: items.item(i).getElementsByTagName(\"Country\").item(0).text,\r\n Location: items.item(i).getElementsByTagName(\"Location\").item(0).text\r\n });\r\n }\r\n\r\n for (var i = 0; i < arrData.length; ++i) {\r\n\r\n //now here, i cant see de alert messages :(\r\n alert('country:'+arrData[i].Country);\r\n alert('state:' +arrData[i].Location);\r\n\r\n }\r\n } catch(erro) {\r\n var items = {error : 'Invalid JSON data'};\r\n }\r\n}\r\n\r\n//Call the service as follows\r\nWS.consumirWS(callback);\r\n\r\n{code}", "attachment": [], "flagged": false, "summary": "Problems, retrieve data WebService HTTPClient within callback function, asynchronous", "creator": { "name": "ludico8", "key": "ludico8", "displayName": "diego", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "ludico8", "key": "ludico8", "displayName": "diego", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Win7", "comment": { "comments": [ { "id": "242265", "author": { "name": "dcassenti", "key": "dcassenti", "displayName": "Davide Cassenti", "active": true, "timeZone": "Europe/Berlin" }, "body": "I cannot reproduce the problem; I tried the code you provided, with the same URL, and I get an error (in fact, the page gives back a 404).\r\n\r\nIf I use a valid URL, everything works fine, and I see the result of the call.\r\n\r\nThanks", "updateAuthor": { "name": "dcassenti", "key": "dcassenti", "displayName": "Davide Cassenti", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-03-14T16:47:03.000+0000", "updated": "2013-03-14T16:47:03.000+0000" }, { "id": "286372", "author": { "name": "mrahman", "key": "mrahman", "displayName": "Mostafizur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "I tested this issue the test code below. I can’t reproduce this issue in latest Ti SDK. It’s working perfect as we expected. Please test this code in latest SDK and let me know if you have any issue. I hope it solve your problem. \r\n\r\nh5. Test Environment\r\n\r\nMAC OS X 10.8.5,\r\nTitanium SDK 3.2.0 GA\r\nIOS Simulator 7.0.3\r\nAndroid 2.3.3\r\nTi CLI 3.2.0\r\n\r\n\r\nh5. Test Code\r\n\r\n{code}\r\nvar win = Titanium.UI.createWindow({\r\n\tbackgroundColor : '#fff'\r\n});\r\n \r\n// Create table\r\nvar table = Ti.UI.createTableView({\r\n\t\r\n});\r\nwin.add(table);\r\n \r\n// Create http client\r\n \r\nc = Titanium.Network.createHTTPClient();\r\nc.setTimeout(10000);\r\n\t\r\nc.onload = function() {\r\n\tvar xml = this.responseXML;\r\n\t// the blog's title is in a node named \"channel\"\r\n\t//var channel = xml.documentElement.getElementsByTagName(\"channel\");\r\n \r\n\t// begin looping through blog posts\r\n\tvar data = [];\r\n\t// blog posts are in nodes named \"item\"\r\n\tvar items = xml.documentElement.getElementsByTagName(\"item\");\r\n\tfor (var i=0;i