Search code examples
jqueryajaxjsonp

json Uncaught SyntaxError: Unexpected token , (comma)


First off, I know there are a load of similar questions where the illegal character is a ":" or "<" ,BUT I couldn't find one where the illegal character is a comma:

Uncaught SyntaxError: Unexpected token ,

I've fiddled with jQuery ajax settings and I get the above error for about 50% of my requests. Weird that some work and some don't, right?

Here's my JS:

            var url = "http://" + domain + "/NewsRoomContentsSvc.svc/getNewsRoomData/" + newsRoomId + "/" + skip + "/" + take + "/" + logged;

        var request = $.ajax({
            type: "GET",
            url: url,
            contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
            crossDomain: true,
            dataType: "jsonp",
            //jsonp:"callback",
            //jsonpCallback:"doNewsRoom",
            newsRoomId: newsRoomId,
            newsroom: newsroom,
            newsRoomParentId:newsRoomParentId,
            cache: false 
        });

        request.done(function (data, textStatus, jqXHR) {

            if (data)
            {
                var CarouselContainer = $("<ul style='width:55000px;'></ul>");
                buildNewsRoom(newsroom, CarouselContainer, data, newsRoomRows, newsRoomCols, newsRoomId, isFull, false);

            }
            else
            {
                //showErrorMsg("hmmmm, no data...");
            }
        })

        request.fail(function (jqXHR, textStatus, errorThrown) {
            if(jqXHR.responseText!=="") 
                showErrorMsg(jqXHR);
           // return false;
        })

My return JSONP looks good to me:

http://ec2-54-76-106-247.eu-west-1.compute.amazonaws.com/NewsRoomContentsSvc.svc/getNewsRoomData/24306184/0/10/1?callback=jQuery1102014052710216492414_1431942943848&_=1431942943849

Half the time it hits the request.fail method with the error "jQuery1102014052710216492414_1431942943848 was not called"

Any suggestions would be greatly appreciated


Solution

  • The json is invalid:

       jQuery1102014052710216492414_1431942943848({"NewsRoomArticles":[{"ArticleId":26539256,"FeedId":, ....}
    

    The atributes "Comments":, "Discussions"and "FeedId": need a value change your db structure to include default values