Sandeep Bansal
Sandeep Bansal

Reputation: 6394

Error response from successful JSONP call

I've created a Cross Origin compatible WCF Service (which took me 4 days of research!) well I've got everything working but now I have a problem with the jQuery request. It's giving me an error I don't know anything about.

Can someone give me an idea on what to do here.

my jQuery:

<script type="text/javascript">
$.ajax({
    url: 'http://localhost:8000/EchoWithGet',
    data: 's=boo!',
    type: 'GET',
    dataType: 'jsonp',
    success: function(res) {
        alert('yay');
    },
    error: function(a,b,c) {
    alert(a + ", " + b + ", " + c);
    }
});
</script>

the error response:

[object Object], parsererror, Error: jQuery17206724130902069609_1340034989481 was not called

If I go to the browser and enter the URL I get:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">OK</string>

Can someone shed some light here.

Thanks

Upvotes: 0

Views: 236

Answers (1)

mkoryak
mkoryak

Reputation: 57968

you should be returning a javascript call from that page. that is how jsonp works.

so the response should look something like this:

jQuery17206724130902069609_1340034989481('some param');

and by default jquery will add the param called callback to the url which specifies the above callback name that the server should respond with.

i recommend reading the ajax docs, especially the sections dealing with jsonp. and looking up how jsonp works

spoon feeding start:

make your server respond with:

iwillreaduponjsonp({'status':'ok'});

make your jsonp request in the clientside like this:

$.ajax({
    url: 'http://localhost:8000/EchoWithGet',
    data: 's=boo!',
    type: 'GET',
    dataType: 'json',
    jsonp: false, jsonpCallback: "iwillreaduponjsonp",
    success: function(res) {
        alert('yay');
    },
    error: function(a,b,c) {
    alert(a + ", " + b + ", " + c);
    }
});

/spoon feeding end

Upvotes: 1

Related Questions