i have a problem when i try to use on iphone this:
Titanium.Network.HTTPClient.onloadit works fine but the same line on android makes problem!!!
this is my code:
DatabaseManager.updateDatabaseFromHTTP = function(lastUpdateTime) { DatabaseManager.databaseHTTPService = Titanium.Network.createHTTPClient(); DatabaseManager.databaseHTTPService.setTimeout(10000); DatabaseManager.databaseHTTPService.onload = function(e) { if (e.source.status == HTTP_OK) { // a trick for making json strings into json objects. try { var serverResponse = eval("(" + e.source.responseData + ")"); if (serverResponse.Areas.length > 0) DatabaseManager.updateDatabaseTable(serverResponse.Areas, "Areas", "AreaID"); Ti.App.fireEvent("databaseLoadCompleted"); } catch(e) { Ti.App.fireEvent("databaseLoadFailed"); } } else Ti.App.fireEvent("databaseLoadFailed"); }; DatabaseManager.databaseHTTPService.onerror = function(e) { Ti.App.fireEvent("databaseLoadFailed"); }; DatabaseManager.databaseHTTPService.open("GET", "http://mobile90.tapuz.co.il/jobs/appsupdate/Trails/GetNewData.aspx?ld=" + lastUpdateTime + "&r=" + Math.random()*1000000); DatabaseManager.databaseHTTPService.send(); }when i debug this code is good on ihpne but on android i get on this line:
DatabaseManager.databaseHTTPService.onload = function(e) //the response: else Ti.App.fireEvent("databaseLoadFailed");do you have a solution for me?
thanks, Eliza
1 Answer
Here is the ajax code that I have used for over a year and works great on both platforms:
var utils = { ajaxInProgress: false, ajax: function (url, callback) { //TODO: queue up next request instead of not executing it. if (!utils.ajaxInProgress) { utils.ajaxInProgress = true; url = url.indexOf("http") > -1 ? url : (tt.config.url + url); Ti.API.info("ajax call: " + url); if (!utils.xhr) utils.xhr = Ti.Network.createHTTPClient(); utils.xhr.setTimeout(20000); utils.xhr.onload = function () { callback(this.responseText); utils.ajaxInProgress = false; }; utils.xhr.onerror = utils.ajaxError; utils.xhr.open("GET", url); utils.xhr.setRequestHeader("User-Agent", "Appcelerator"); utils.xhr.setRequestHeader("Accept-Encoding", "gzip,deflate"); utils.xhr.send(); } else Ti.API.info("ajax request in progress so not making new one"); }, ajaxError: function (e) { utils.ajaxInProgress = false; Ti.API.info(JSON.stringify(e)); Ti.API.info("ajax error: " + e.error); } }
Your Answer
Think you can help? Login to answer this question!