0

i am trying to get jsonp call working with jquery and my asp.net-mvc site. I found this article which i tried to copy but i am not getting a breakpoint in my callback:

Here is my jquery code:

         $.ajax({
                url: "http://www.mySite.com/MyController/Terms",
                type: "GET",
                dataType: "jsonp",
                timeout: 10000,
                jsonpCallback: "localJsonpCallback"
            });

            function localJsonpCallback(json) {
                 var terms = json.HTMLText;
                 $("#term2").html(terms);
            }

and here is my controller code:

    public JsonpResult Terms()
    {
        var data = GetData();
        return this.Jsonp(data);
    }

where JsonpResult and this.Jsonp are defined as per this page:

so I can't seem to get a callback but when I open up firebug script section, I do see a file listed when is the url about and has:

 Terms?callback=localJsonpCallback

and when i look into the content I see the correct json object content:

localJsonpCallback({"HTMLText":"PRIVACY POLICY: Your privacy is very important to us"});

so this tells me the data is coming back to the client but the callback doesn't seem to be firing and the text input is not being populated.

Can anyone find an issue with what i am doing or have any explanation on why this wouldn'nt work?

1
  • try with url: "http://mySite.com/MyController/Terms" Commented Sep 26, 2011 at 5:30

1 Answer 1

1

You don't have a success function defined for your ajax request. The jsonpCallback parameter that you are using only defines the name of the query string parameter that will be used by the server to wrap the JSON response into.

So try like this:

$.ajax({
    url: 'http://www.mySite.com/MyController/Terms',
    type: 'GET',
    dataType: 'jsonp',
    timeout: 10000,
    jsonp: 'jsoncallback',
    success: function(json) {
        var terms = json.HTMLText;
        $('#term2').html(terms);
    }
});

Also checkout the following answer.

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

2 Comments

I still don't get the callback using the format you listed in your answer . . any other thoughts? In fact, with this way, I now no longer even see this request in firebug at all.
I actually got it working using your answer from another question: stackoverflow.com/questions/4795201/…

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.