jeudi 28 janvier 2016

PJAX with Laravel getting error notice on form submission

I've got pjax working fine in most instances, but when submitting a form, I'm getting an odd error message in the console:

Uncaught TypeError: Cannot read property 'tagName' of undefined

I've tracked this down to line 123 in pjax.js, which is:

 function handleSubmit(event, container, options) {
    options = optionsFor(container, options)

    var form = event.currentTarget

    if (form.tagName.toUpperCase() !== 'FORM') //error occurs here
        throw "$.pjax.submit requires a form element"

    var defaults = {
        type: form.method.toUpperCase(),
        url: form.action,
        container: $(form).attr('data-pjax'),
        target: form
    }

The code still seems to fire correctly, but I'd like to clean up the errors.

So, I added a console.log(form) just before that to see what was happening, and here's what I got:

undefined
Uncaught TypeError: Cannot read property 'tagName' of undefined
<form method="POST" ...

Looks like it must be firing the method handleSubmit() twice, once with blank data and once with the form, but I can't figure out why. Here's where I fire pjax:

$(document).on('submit', 'form[data-pjax]', function(event) {
  $.pjax.submit(event, '#pjax-body');
})



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire