Closed Priler closed 8 years ago
If the form handled by the FW_Form
helper, you can try this solution
Seems like it handled with FW_Form, but this not works.
This error in console fw-form-helpers.js:41 Uncaught TypeError: Cannot read property 'errors' of undefined
For some reason ajax request always return 0 in Network tab. How this can be fixed?
The form is registered here on this action. Maybe that action is executed later than wp_ajax_*
action
@moldcraft How it may be fixed?
jQuery(function($){
var selector = 'form[data-fw-form-id="learning-quiz-quiz-form"]';
$(document.body).on('submit', selector, function(e){
e.preventDefault();
var $form = jQuery(this);
// get submit button
{
var $submitButton = $form.find(':submit:focus');
if (!$submitButton.length) {
// in case you use this solution http://stackoverflow.com/a/5721762
$submitButton = $form.find('[clicked]:submit');
}
// make sure to remove the "clicked" attribute to prevent accidental settings reset
$form.find('[clicked]:submit').removeAttr('clicked');
}
jQuery.ajax({
type: "POST",
url: $form.attr('action'),
data: $form.serialize() + ($submitButton.length ? '&'+ $submitButton.attr('name') +'='+ $submitButton.attr('value') : ''),
dataType: 'html'
})
.done(function(html){ window.hhh = html;
$form.closest('.fw-learning-quiz').html(
$('.fw-learning-quiz', html).html()
);
}).fail(function(jqXHR, textStatus, errorThrown){
alert(String(errorThrown));
});
});
});
Hi!
Is there a way to make Quizes to be Ajax?