0

I am quite new to javascript and calling APIs. Here is my code. I am trying to call an API on apiary.

The API call is linked to an event listener (button click):

$.lbl_sloganLabel.addEventListener('click', function(e) {
    // call api function
    if (Titanium.Network.online) {
        apiHelper.APIGetRequest('http://xxxxxxxx.apiary-mock.com/methodname', 
            function(e) {
                var status = this.status;
                if (status == 200) {
                    alert('works');
                }
            }, function(err) {      
                alert('Unknown error from api');
            }
        );
    } else {
        alert('No internet connection found');
    }
});

Currently if I make a request to googleAPI, I get a successful response (i.e. a connection is established), if I try to make a request to apiary ,it fails.

I am not sure if this is the right way to do this, but from my understanding after the apiHelper has established a connection, I should be able to accessed the object as normal ie. .method name.

Anyway I need some clarification on this, cheers.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
bobo2000
  • 1,779
  • 7
  • 31
  • 54
  • What are the libraries you are using? I unfortunately don't have much knowledge about titanium, nor what apiHelper is. – Almad Apr 07 '14 at 13:37
  • Eventually, what 'it fails' means? Do you have any traceback in browser console, or the response to the request that failed? – Almad Apr 07 '14 at 13:38

1 Answers1

0

Do you have CORS enabled in settings for that API in Apiary?

Almad
  • 5,753
  • 7
  • 35
  • 53