This is a migrated thread and some comments may be shown as answers.

Remote JSON data problem

1 Answer 86 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Greg
Top achievements
Rank 1
Greg asked on 25 Jul 2014, 03:33 AM
I'm just trying to connect to my own website and get some JSON data and it always returns an error. If I change the dataType to "json" and make the url to an 

identical local JSON file it works just fine. 

What am I doing wrong here?
$(document).on('pageinit', '#home2', function(){
    //var url = 'data/projList2.json';
    //var url = 'data/projList30.json';
 
 
    $.ajax({
        url: url,
        dataType: "jsonp",
        async: true,
        success: function (result) {
            ajax.parseJSONP(result);
        },
        error: function (request,error) {
            alert('Network error has occurred please try again!');
        }
    });        
});

1 Answer, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 29 Jul 2014, 03:29 PM
Hi Greg,

As far as your web service returns JSON-formatted results you need to pass 'json' to the 'dataType' configuration option of the jQuery.ajax() object. Please note that in the success handler of the request there is no need to use ajax.parseJSON() as the result is already formatted as JSON.

For using the 'jsonp' in the 'dataType' configuration option the server needs to know how to respond with accordingly formatted results, e.g. wrap the results in a callback function call that can be accessed by the client-side JavaScript.

Please, let us know if you have further questions.

Regards,
Anton Dobrev
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
General Discussion
Asked by
Greg
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Share this question
or