TTCG TTCG - 1 year ago 112
JSON Question

Jquery AJAX JSONP not working

First of all, I am very new to WebAPICore and JSONP and trying to get the JSON data from WebAPICore.

I have built the test API which returns JSON object and it's working fine in the Browser. I did configure the CORS to allow cross origin access too.

I did the test JSONP call as shown in

Working Code as shown in the Example

$.getJSON("", function (json) {

Not working even though it did return the JSON data back

$.getJSON("http://localhost:1569/offerings/5?callback=?", function (json) {

I am getting the 'Unexpected token' error when calling my service.

I couldn't figure out why it's not working only with my service. Please see the following image about the errors, return jsons and Debugging in Chrome Console.

enter image description here

The only difference between GitHub API and my API is the formatting of JSONs.

Do I need to do special formatting or encoding in my service to return the JSON data for JSONP?

My Test code which returns JSON Object from WebAPICore

public Offering Get(int id)
return new Offering()
OfferingID = id
, CourseName = "TestCourse"
, CourseCode = "TestCode"
, Description = "My Description"

Answer Source

If someone has ever encountered this error... here is the working code:

                url: 'http://localhost:1569/offerings/5',
                success: function (result) {

just change $.getJSON to traditional $.ajax call