var app = {
// Application Constructor
initialize: function() {
$.getJSON( "http://domain.com/api/data")
.done(function( json ) {
alert("SUCCESS!");
})
.fail(function( jqxhr, textStatus, error ) {
alert("Failure! Error: " + error);
});
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
app.initialize();
When running the script above I see the following alert: "Failure! Error: "
. The error
argument has no value so I'm having trouble finding where the problem actually is. Most other questions with this title have the best answer as not adding the domain of the endpoint, I can rule that out:
To view my config.xml file click here.
You will see that I set origin="*"
which should allow communication with all endpoints no matter what domain. Any ideas as to why this is happening?
UPDATE
It is something to do with my server as other servers show the "SUCCESS" alert message. Still yet to find the specific issue, though. For some reason my server doesn't seem to like cross origin requests... I have disabled the firewall but no success there. Would just like to confirm that the requests works perfectly fine when on the same URL.
Server sites-enabled/000-default.conf:
<VirtualHost *:80>
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods "GET, OPTIONS"
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>