0

i am trying to make a ajax call with dataType JSONP from my client side script, the service uri belongs to a restful wcf service which hosted locally.

Below is my client side script:

function callback() {
     alert("callback");
 }
 

     $.ajax({
         url: "http://localhost:999/Service1.svc/Get/rajesh",

         // the name of the callback parameter
         jsonp: "callback",

         // tell jQuery we're expecting JSONP
         dataType: "jsonp",

         // work with the response
         success: function (response) {
             console.log(response); // server response
         },
         error: function ( jqXHR, textStatus, errorThrown) {
             alert("errorThrown: " + errorThrown + " textStatus:" + textStatus);
        }
     });

i am get below Errors:

1) Error Alert message enter image description here

errorThrown: Error: jQuery1910367527295252279_1387528759305 was not called textStatus:parsererror

2)Error at console

enter image description here

console error json object is incorrect but i think it is current. any help is appreciated

3
  • Try putting it inside $(function() {}) and check if that makes any difference Commented Dec 20, 2013 at 8:42
  • @RononDex: It has nothing to do with DOM ready. Commented Dec 20, 2013 at 8:44
  • well, that jquery[number] you got there is common for jquery. It adds those id's on html elements that it uses in the dom. That's why I thought it might make a different Commented Dec 20, 2013 at 8:45

2 Answers 2

3

From the error, it looks like your server is responding with JSON, not JSONP, as the error is quoting:

{"GetEmployeeResult":"success"}

...which is JSON, but a JSONP response would look like:

jQuery34978249823_23049820394({"GetEmployeeResult":"success"})

...where the function name jQuery34978249823_23049820394 comes from the callback parameter in the request (and will vary every time).

To correct it, have the server return JSONP, or change your $.ajax call to use JSON (assuming the SOP isn't an issue).

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

4 Comments

I tried by replacing jsonp with Json, still it is going to error function display jqXHR.status as 0 and textStatus as error
@VivekP: That would suggest you're trying to do something cross-origin and JSONP is the better option.
@Crowder Yes, to achieve cross-origin i used jsonp.
@VivekP: Right. So the server has to respect its side of that contract, and return JSONP, not JSON.
0

See answer available Here:

How to natively enable JSONP for existing WCF service?

For a possible solution. It sounds like you need to re-configure your wcf to return JSONP and not JSON.

Comments

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.