user2020584
user2020584

Reputation:

Jquery-Json.ParseUnexpected Character

I have this following ajax to call my service which fetches some records from the Database and fills it in my frontend...but i get the json:unexpected character error...can u please help me in solving this ...

'http://localhost/WcfService/Service1.svc/remarksList';

    var tempyear="";

    $.ajax({
                    url: urlToHandler,
                    data:JSON.stringify({oei:{"reqNo1":reqNo,"loginid":userid}}),
                    type: 'POST',
                    dataType:"json",
                    contentType: 'application/json',
                    success: function(data) {    

                    alert(data.fillRemarksListResult);
                    myData = JSON.parse(data.fillRemarksListResult, function (key, value) {
        var type;
        if (value && typeof value === 'object') {
            type = value.type;
            if (typeof type === 'string' && typeof window[type] === 'function') {
                return new (window[type])(value);
            }
        }
        return value;
    });
    alert(myData);
        $.each(data.fillRemarksListResult,function(key,val){


                alert(val.rmrkreqNo1);
                        });
                    },
                    error: function(data, status, jqXHR) {                       
                        alert('There was an error.');
                    }
                }); // end $.ajax

});

Now i get this error :

Json.parse:unexpected character myData=JSON.parse(data.fillRemarksListResult, function (key, value) {

Upvotes: 0

Views: 2153

Answers (1)

Legolas
Legolas

Reputation: 163

You can either use dataType:"json" or JSON.parse..but not both..bcoz it already parses the data and sends it..reparsing ll throw an error obviously !!

Upvotes: 1

Related Questions