0

I'm calling an MVC4 Web API service that I am building just to learn MVC and Web API. I'm having an issue with my jQuery call. I keep getting an unexpected token error.

http://jsbin.com/ayuvak/1/edit

Any help would be greatly appreciated. I suspect this is very easy but I was up until 4:00 AM working on another project and cannot focus to save my life.

$(document).ready(
      function(){
        $.ajax({
            url: 'http://sub.robertkaucher.com/api/Subtitles/5?callback',
            type: "GET",
            dataType: "jsonp"
        });
        function callback(data) {
            $('#divContent').html(data.SubFile);

        }
      });

1 Answer 1

1

You are asking your service to return JSONP, but the service is returning JSON as content-type. Thats why you are getting this error. Can you try making the response header to return content-type to text/javascript instead of application/json ?

Also a better way to fix cross origin policy is to use CORS. This is a great post explaining how to enable CORS support in Web API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.