1

I've built a simple web service using the Web Api and I want to consume it from a simple mVC view using jQuery. I'm developing on localhost and consuming the service from Azure, which is why I'm using jsonp.

When I run my jQuery I view in Fiddler and the request is successful and json sent back but the .Ajax function returns these errors:

NaN, parsererror, and callback was not called

<script>
    $(function () {

        var callback = function(data) {
            alert(data);
        };
            $.ajax({
                url: 'http://itjobsdirect.azurewebsites.net/api/values/getbytitle?title=developer',
                type: 'GET',
                dataType: 'jsonp',
                jsonpCallback: 'callback',
                success: function (data) {
                    $('#main').text(data);

                },
                error: function(jqXHR, textStatus, error) {
                    alert(jqXHR.status + jqXHR.message);
                    alert(textStatus);
                    alert(error);
                }
            });



    });
</script>

I found this question: JsonP with Web Api is it still relevant?

Thanks for your help!

1 Answer 1

1

Yes, the link to that question you have there is still relevant.

ASP.NET Webapi doesn't ship with a default formatter that understands the dataType of 'jsonp' and so the solution here is to add a custom JsonpMediaTypeFormatter (as shown in the answer for the questions you have linked).

Sign up to request clarification or add additional context in comments.

1 Comment

Used revealing modules in the end with Handlebars templates

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.