I have a page with infinite scroll. The ajax functionality works fine for forms existing on the page when it initially loads, but doesn't work for forms loaded from the inifinite scroll ajax feature. I've searched for about 5 days trying to find a answer and haven't yet. Here is a portion of the javascript:
$("form:not(.member)").submit(function() {
var status_id = $('#status_id').val(),
etc..........
The reason for the :not(.member)
part is so the other forms on the page, such as the search form, aren't included in the script.
I've tried
$("form:not(.member)").live('submit', function() {
and
$("form:not(.member)").on('submit', function() {
as well as
$('body').delegate('submit', 'form:not(.member)', function() {
None of these are working on the forms loaded AFTER the initial page load. Does anyone have any other suggestions? I'm using jquery 1.7.1 by the way. I've also tried
$("form:not(.member)").bind('submit', function()
Your syntax is just wrong, that's all. Those functions should work. Using
.on()
as an example:Where
someListener
is an ancestor element that is NEVER destroyed by the AJAX function. If you're trying to bind to an element that gets destroyed, your listener gets lost as well.Have to admit, I don't think the
'form:not(".member")'
part doesn't look right to me, either. Are you sure that's the correct syntax fornot
? I'm just taking your word for it here.There's a better way anyhow: either #someListener is an ancestor that does not have your other forms within (like the search form), or you give this specific kind of form a class. So instead of excluding
.member
forms, you would TARGET just this kind of form:Or, if the Ajax content block (form and all) has a wrapper of some sort, you could add a class to it (say,
".ajaxBlock"
) and do it this way instead: