Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
my JSON response is like this { "items":[{"s": "2","f": "host","m": "hi..Smile | :) "}, ] }
 
I wrote the following code to read the JSON data. but not getting the any value. alert box also not working. If any one please inform me where I did mistake ...
 
$.ajax({
 
url: "ChatHandler.aspx?action=chatheartbeat",
cache: false,
dataType: "json",
success: function (data) {
 
$.each(data.items, function (i, item) {
 
if (item) { // fix strange ie bug
 
chatboxtitle = item.f;
 
alert(item.m);
 
}
});
});
Posted 4-Jan-13 2:19am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Alert might not work by one of the following reasons:
  • data.items is empty; then the function in the $.each loop is never called;
  • data is undefined; then the exception is thrown when you try to dereference it by getting data.items; so the rest of the script's call stack is skipped; note that unhandled exceptions are not shown;
  • the function in the loop is called but exception is thrown inside it.
 
To find out which case takes place you can use the step-by-step debugging or handle exceptions and provide test output.
 
—SA
  Permalink  
Comments
GopinathGuru at 4-Jan-13 8:03am
   
Hi Sergey Alexandrovich,
I am using firebug to check the json response following things are came in my browser
{ "items":[{"s": "2","f": "host","m": "hi.. "}, ] }. Only thing is i am not getting the values in jQuery.How will i fix the above bug.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 235
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100