{ "id": "62739", "key": "TIMOB-2107", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "10100", "description": "This issue won't be actioned.", "name": "Won't Do" }, "resolutiondate": "2020-01-09T18:33:03.000+0000", "created": "2011-04-15T03:10:38.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "core" ], "versions": [ { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2020-01-09T18:33:03.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": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}
When HTTPClients are opened in synchronous mode (the third\r\nparameter set to false), the send call returns before executing the\r\nattached callbacks. I know it seems weird wanting to use callbacks\r\nwith a synchronous call, but this behaviour seems to be expected of\r\nother XHR like objects by libraries like jQuery and SpazCore.
\r\nTry running this code to reproduce the issue:
\r\n var bool, xhr;\r\n xhr = Titanium.Network.createHTTPClient();\r\n bool = false;\r\n xhr.open(\"GET\", \"http://api.twitter.com/1/help/test.json\", false);\r\n xhr.onreadystatechange = function() {\r\n Ti.API.debug(\"Ready State change to \" + xhr.status);\r\n if (xhr.status === 200) {\r\n Ti.API.debug(\"Setting bool to true\");\r\n bool = true;\r\n }\r\n };\r\n xhr.send();\r\n Ti.API.debug(\"Bool is: \" + bool);
\r\n
\r\nOutput I get from iPhone SDK v4.1, Titanium Mobile SDK\r\nv1.4.0
\r\n\r\n[DEBUG] Bool is: false\r\n[DEBUG] Ready State change to 200\r\n[DEBUG] Setting bool to true
\r\n
\r\nWhat I think I should see:
\r\n\r\n[DEBUG] Ready State change to 200\r\n[DEBUG] Setting bool to true\r\n[DEBUG] Bool is: true
\r\n
\r\nIf you run this code in chrome in a console on\r\napi.twitter.com:
\r\n var bool, xhr;\r\n xhr = new XMLHttpRequest();\r\n bool = false;\r\n xhr.open(\"GET\", \"http://api.twitter.com/1/help/test.json\", false);\r\n xhr.onreadystatechange = function() {
\r\n
\r\n\r\n\r\n
\r\n
\r\n\r\nconsole.log("Ready State change to " + xhr.status);\r\nif (xhr.status === 200) {\r\n console.log("Setting bool to true");\r\n bool = true;\r\n}
\r\n
\r\n\r\n\r\n\r\n\r\n
\r\n };\r\n xhr.send();\r\n console.log(\"Bool is: \" + bool);\r\n
You get the above expected output:
\r\n\r\nReady State change to 200\r\nSetting bool to true\r\nBool is: true
\r\n
\r\nCan Titanium's XHR implementation be changed to conform?
Confirmed this issue persists in the mobile SDK v1.4.1.1
Any update on this folks? I'd love to use some of the stuff this\nbreaks!
XHR spec does say that these are supposed to be synchronous, but\nwe're purposefully ASYNCHRONOUS. At least on the iOS side, we need\na way to force events to fire synchronously, for cases like\nthis.