1

Basically response consist of two things JSON Array and isValid(flag)

I can get flag value successful But it gives the null var resJSON = jQuery.parseJSON(data.notification);. I debug my script in chrome console but json response exist in data.

Might be following code and console result help you to understand my problem!

function getNotificationById(notificationId) {
    jQuery.ajax({
        type: "POST",
        url: "<%=request.getContextPath()%>/GetNotifications/",
        dataType : "json",
        data: {"operation": "getNotificationById", "notificationId": notificationId},

        success:function(data){ 

            var resJSON = jQuery.parseJSON(data.notification);
             //   ^-- here is null  

            if (data.isValid) {
            //    ^-- response is true          
                jQuery.each(resJSON,function(i, value){
                    console.log(value.Body);
                });
            }
        }
    });
}

Chrome Console Result:

Chrome Console Result

Edit I have tried following solutions:

var resJSON = data.notification;  // Chrome Console return **undefined**
5
  • 3
    try var resJSON = data.notification;. I think you are trying to parse an object instead of string Commented Aug 20, 2015 at 6:55
  • 2
    Since you have set dataType: 'json', data.notification will be an object.. so no need to parse it agaibn Commented Aug 20, 2015 at 6:56
  • @Cerlin I have tried it gives "resJSON = undefined," in console Commented Aug 20, 2015 at 6:59
  • console log the object and see if the property exists or not. like console.log(data); or console.dir(data); Commented Aug 20, 2015 at 7:01
  • 1
    @CerlinBoss I get it .. that was my typo mistake ... I was getting "notificaiton" and calling "notification".. Thank you for help Commented Aug 20, 2015 at 7:05

1 Answer 1

1

You have a typo. The data as shown in traces are included in data.notificaiton and not data.notification

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.