0

I have an application in MobileFirst, and use an ajax function to call REST WS created with IBM RAD, this is the AJAX function:

$.ajax({
    type: "GET",
    url: "http://localhost:9080/myproject/rest/helloworld/",
    contentType: "text/plain",
    async: false,
    success: function (response) {
            var sHelloWorld = response;
            $("#prueba").empty();
            $("#prueba").append(sHelloWorld); 
    },
    error: function (result) {
        alert('ERROR ' + result.status + ' ' + result.statusText);
    }
});

But I get error

"Access Denied result.status = 0"

Could you be related to this article? Is it possible to specify a port in a ajax call

Community
  • 1
  • 1
Eladerezador
  • 1,277
  • 7
  • 25
  • 48

1 Answers1

1

Since you have likely created a mobile web app (Android, iOS, etc...), note that you're pointing to localhost. That means that your AJAX request is pointing to the device and not to an actual destination.

Replace "localhost" with the IP address of the backend you are attempting to connect to.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Just an fyi, if using an Android emulator, change localhost to 10.0.2.2 as specified by Android Emulator docs http://developer.android.com/tools/devices/emulator.html#emulatornetworking – Victor Sosa Jun 26 '15 at 13:59
  • @Eladerezador, If your question is resolved please mark as Answered. – Idan Adar Jun 26 '15 at 14:01