Xmlhttp.send(); fail


#1

I have a problem, i need open and copy to file xml from server, but my app fail in xmlhttp.send();.

If link of file is local (in device), my app work, but i need, the open file of server, and if Change to o local, do Servidor, Erro

Tanks for help


#2

Your question is a little unclear, but it sounds like you might be trying to save a file directly to a server? If that is the case, Javascript cannot do that, you will need some kind of API on the server to accept the file. You might want to research creating a RESTful API for saving files.


#3

The idea is to make an application that every day, go to a server, see a file of type xml or json, whatever, and update the local database so that the user can access the application even in offline mode and it got the data. This file contains activities that IRAM realiar in one place hence be necessary to update it daily.
I have this:

function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
                tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id INTEGER, NEVENTO, DATA, HORA, LOCAL, FREGUESIA, CATEGORIAS, DESC_BRE, DESC, LAT, LON)');
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    var xmlhttp = new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.open("GET", "https://dl.dropboxusercontent.com/u/2906080/event_catalog.xml", false);	
                xmlhttp.send(null);
                xmlDoc = xmlhttp.responseXML;
                var x = xmlDoc.getElementsByTagName("EVENT");
                for (i = 0; i < x.length; i++)
                {
                    var xName = x[i].getElementsByTagName("NEVENTO")[0].childNodes[0].nodeValue;
                    var xData = x[i].getElementsByTagName("DATA")[0].childNodes[0].nodeValue;
                    var xHora = x[i].getElementsByTagName("HORA")[0].childNodes[0].nodeValue;
                    var xLocal = x[i].getElementsByTagName("LOCAL")[0].childNodes[0].nodeValue;
                    var xFregsia = x[i].getElementsByTagName("FREGUESIA")[0].childNodes[0].nodeValue;
                    var xCategoria = x[i].getElementsByTagName("CATEGORIAS")[0].childNodes[0].nodeValue;
                    var xDescbre = x[i].getElementsByTagName("BRE")[0].childNodes[0].nodeValue;
                    var xDesc = x[i].getElementsByTagName("DESC")[0].childNodes[0].nodeValue;
                    var xLat = x[i].getElementsByTagName("LAT")[0].childNodes[0].nodeValue;
                    var xLon = x[i].getElementsByTagName("LON")[0].childNodes[0].nodeValue;
                    tx.executeSql('INSERT INTO DEMO (id, NEVENTO, DATA, HORA, LOCAL, FREGUESIA, CATEGORIAS, DESC_BRE, DESC, LAT, LON) VALUES ("' + i + '", "' + xName + '", "' + xData + '", "' + xHora + '","' + xLocal + '", "' + xFregsia + '","' + xCategoria + '", "' + xDescbre + '","' + xDesc + '","' + xLat + '","' + xLon + '")');
                }

this code run in phonegap, but i need the change to ionic and, fail :confused:


#4

I’m still not very clear what the actual problem is, but realize that phonegap and ionic are not comparable. PhoneGap and Cordova are comparable, which Ionic uses Cordova by default. PhoneGap is an Adobe version of the Apache project Cordova, both of which enable you to build a mobile app using html/css/javascript. Most of Ionic is really only focused on the html/css/javascript portion, though it does provide scaffolding and tools for Cordova.

I’m not sure what is failing, so its hard to know what might be wrong. However the problem might be that you are probably using Cordova, and there may be some difference between your PhoneGap setup and the Cordova setup.


#5

Tanks @gnomeontherun for explanation I solved my problem by changing the file. XML for. json, and making your copy from the server to the device.
Again, thanks for the help


#6

Good, XML is a pain to parse. Slso you shouldn’t have to use code that was designed to catch if a browser is IE6, only concern yourself with the mobile platforms. If you are using JSON, then you can use the angular $http service (or a $resource service for more features) to make your requests for external data.