Home > Ajax, JavaScript, jQuery, Programming, Web, Web Service > Invalid JSON primitive in Chrome

Invalid JSON primitive in Chrome

I ran into the strangest problem today.  My Ajax call to my web service failed with the error “Invalid JSON primitive”, but only in Chrome…it worked in all my other browsers.

After reading up a bit it seemed to be a problem with the data being sent to the service.  Strange enough I was not sending any…and that turned out to be the problem. 

So for whoever runs into this problem, try setting the data parameter in jQuery to nothing, like in the code below.

    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "DataService.asmx/ProjectList",
    dataType: "json", //response type
    data: "{}", // IMPORTANT
    success: function(msg, success) {
        if (success == 'success') {
            //good response
            data = eval(msg.d);
            // attach the template
            $("#slideshow").setTemplateElement('projectFaderTemplate', null, { runnable_functions: true });
            // process the template
        } else {
            $('#msg').html('Error: ' + msg.d); //service returned an error
    error: function(msg, e) {
        $('#msg').html('Error.  Please contact Technical.'); //error with ajax call

Hope this helps someone.

  1. Britney Spears
    28 September 2010 at 13:22

    Hi Pieter.
    Thanks! This was driving me nuts. The call to my webservice worked fine on Chrome 5, but failed on Chrome 4 for no apparent reason.

    • Pieter
      28 September 2010 at 14:04

      Glad I could help.
      It sounds like it’s been fixed in 5 then…that’s good news 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: