0

I am getting this "Json ParserError" in chrome console when looping through the response returned by web service. I am using dataType: jsonp as i am trying to call cross domain ajax call in development environment, BUT stuck with this error.

$.ajax

function callajax1() {
           $.ajax({
                url: "http://www.sample.com/Integration/PhotoCompetitionHelper.asmx/SayHello",
                data: "",
                dataType: 'jsonp',
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                jsonpCallback: 'showResult',
                success: function (data) {
                    console.log(data.d)
                },
                error: function (data, status) {
                    console.log("FAILED:" + status);
                }
            });
        }

        function showResult(data) {
            console.log(data.d);
        }

WebService

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string SayHello()
    {
        return "Hello";
    }

JSON Response

{"d":"Hello"}

ERROR

FAILED:parsererror 
patel.milanb
  • 5,822
  • 15
  • 56
  • 92
  • 1
    specify a different name for callback and define the function in your javascript. 'alert' being a reserved keyword cant be your callback function. also, your response is not jsonp.it should be of the format callback(<>) refer http://stackoverflow.com/questions/19489976/cross-domain-ajax-request-to-a-json-file-using-jsonp/19491482#19491482 for a helloworld example. – Saranya Nov 07 '13 at 12:06
  • did that still getting the same error – patel.milanb Nov 07 '13 at 12:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40733/discussion-between-patel-milanb-and-saranya) – patel.milanb Nov 07 '13 at 12:23

1 Answers1

0

You are getting the parser error because when your dataType is jsonp, it expects a script and not json. Try to include a callback function.

Saranya
  • 1,988
  • 16
  • 20