I'd like to hook into a ajax callback for a specific form that's using unobtrusive ajax. The ajax call is no problem with this standard form using unobtrusive ajax:
<form action="/xyz" data-ajax="true" data-ajax-method="POST" id="someformid" method="post">
<input type="text" name="bla" />
<button>submit</button>
</form>
My first approach was this:
var form = $("#someformid");
$(document).ajaxComplete(function (e, request, options) {
// is not hitting here
});
But that doesn't seem to work. This approach hits the handler, but not just for the desired form. But for all ajaxComplete events.
var form = $("#someformid");
form.submit(function (eevent) {
$(document).ajaxComplete(function (e, request, options) {
// this hits ok. but not just for this form
});
});
Next option would be to use the "data-ajax-success". but that doesn't seem to supply the form context.
So the question: How do I hook up a ajaxComplete event for just one form exclusively.
Note: I'd like to avoid workarounds like matching the url or adding some unique id to the query.
Thanks!
From the
.ajaxComplete()
docs:So, the way I read this is, if you know you'll be running a specific URL (your php processing script), then you can pass that URL in the settings to the
.ajaxComplete()
method.... (in your case, "/xyz")