1

I'm building native web app with jquery mobile and phonegap. Data is loaded from external server. Now data must be loaded using ssl, but I'm getting error:

NETWORK_ERR: XMLHttpRequest Exception 101

I tried Chrome REST client and eveerything works just fine.

Code:

WebService.prototype.execute = function (url, params) {
    var result = {
        HttpResponseObject : {},

        onSuccess : function (data) {       
            result.HttpResponseObject.response = JSON.parse(data);
        },

        onError : function (XMLHttpRequest, textStatus, errorThrown) {          
            $.mobile.hidePageLoadingMsg();          

            // TODO some logging for errors
            console.log(JSON.stringify(XMLHttpRequest));
            console.log(JSON.stringify(textStatus));
            console.log(JSON.stringify(errorThrown));       
        }
    };

    $.ajax({
        url:            url,
        type:           'POST',
        async:          false,
        data:           JSON.stringify(params),
        dataType:       'text',
        contentType:    'application/json',
        error:          result.onError,
        success:        result.onSuccess
    });

    return result;
};
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Robertas Setkus
  • 3,075
  • 6
  • 31
  • 54

2 Answers2

1

This is what I do in order to use ajax to query an external API...

 $.ajax({
        type: "GET",
        url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=[myAPIKey]&q=" + movie.title + "&page_limit=1",
        contentType: "application/json; charset=utf-8",
        crossDomain: true,
        dataType: 'jsonp',
        success: function (msg) {
            ...awesome code here
        }});

The key here is the "crossDomain: true" line (maybe the dataType: 'jsonp' for some services too).

Andrew Gene
  • 175
  • 2
  • 6
0

This will help you - ajax calls are not working on external urls, but there is a way around that:

How to call external url in jquery?

Community
  • 1
  • 1
m7o
  • 901
  • 5
  • 7