paulirish/infinite-scroll — Issue #118: Add a callback to json request to detect end of content
Author: yehiasalam
Created: 2012-01-13 12:21:35+00:00
State: open

Hi,

Currently the json request in the retrieve function check whether the json object returns any values, and if that not the case it calls the _error function with an "end" argument, however practically in many cases the return json follow the format
{
success: true,
count: 12,
data: [{id:dsf,etcc}]
}

and when the data field is empty, that's signify the end of the stream, so i think we need to implement a callback function to check whether the return object from the json call signifies the end of the stream, in my case i had to hardcode like this:
```php
case 'html':
case 'json':

instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
$.ajax({
// params
url: desturl,
dataType: opts.dataType,
complete: function infscr_ajax_callback(jqXHR, textStatus) {
condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === "success" || textStatus === "notmodified");
// modified to allow end of deals detection
var rResultCount = ($.parseJSON(jqXHR.responseText)).data.length;
if (condition && (rResultCount > 0) ){
instance._loadcallback(box, jqXHR.responseText)
}else{
instance._error('end');
}
}
});
```
since there were no options no extended it or override it. I can contribute with the callback function needed if that would help.