Why isn't data being returned to the getJSON success handler?
Question by typoknig
I was calling getJSON
and looping through the results like this and everything was working great:
$.getJSON( base_url + 'search/drill_down',{
nextSelectName: nextSelectName,
thisSelectName: thisSelectName,
itemId: itemId
}, function( r ) {
$.each( r.items, function( k, v ) {
//do stuff
});
});
Now on a certain condition I need to return some HTML data, but I still need JSON for my original condition, so I figured I would just encode my HTML as JSON, but the data never returns! The original code still works fine, it is only when I’m trying to return HTML encoded as JSON that things blow up.
$.getJSON( base_url + 'search/drill_down',{
nextSelectName: nextSelectName,
thisSelectName: thisSelectName,
itemId: itemId
}, function( r ) {
alert('working!'); // Not hitting this!
if(r.tabs){
$.each( r.tabs, function( k, v ) {
var html = v[ 'html' ];
return $('#content').html(html); // No need to continue, there is only one HTML string and no items.
});
}
$.each( r.items, function( k, v ) {
//do stuff
});
});
I have a break point on the server (using CodeIgniter) and everything there looks good. I checked checked the HTML I encoded as JSON and it is valid JSON. Why is the JSON generated by my server not making it back to the getJSON
success handler?
Answer by Starx
The only explanation is the request was flaud, and reason might be many. One might be requesting on a wrong place. Check using
console.log(base_url + 'search/drill_down');