jscroll
jscroll copied to clipboard
enable using $.ajax instead of load() using a callback
trafficstars
Let client use AJAX (e.g. POST) instead of just HTML loading. This can be useful:
- Let the server know how the previous page worked out (e.g. how much conversion, how long the user spent on it, etc.)
- Items are returned in non-HTML (e.g. JSON; especially the link to the next page) and need deserialization before jscroll gets to process them.
This is done by hooking options.loadFunc and providing an arbitrary asynchronous loading function there.
Of course load() is still the default.
+1 for this feature.
The way you wrote it won't work, as the this scope is gone in your callback function. So change
target.load(data.nextHref, function (r, status) { callback(status); });
to
target.load(data.nextHref, function (r, status) { $.proxy(callback, target)(status); });
N.B. I don't have push access to your branch, so I am writing this as a comment instead of fixing your PR.
@pklauzinski; Any change this PR will be merged?
+1 for this feature