Voyager: POST is always triggered twice

Created on 25 Aug 2017  路  4Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.4.28
  • Voyager Version: 0.11.14
  • PHP Version: 7.1.3-3
  • Database Driver & Version: MySQL

Description:

After some weird behavior on some breads I found out using a Proxy that every POST request is always triggered twice for some reason. For most scenario that does not matter but in some cases it duplicates data or execute the logic two times.

image

image

image

The difference is that the first it has the header X-Requested-With: XMLHttpRequest and the response is 200. The second time is executed it does not have X-Requested-With: XMLHttpRequest and the response is 302 but sometimes is 200 also.

Steps To Reproduce:

  1. Open a web proxy or Network tab in Chome
  2. Execute a BREAD save
  3. Two POST are triggered, one with XHR and one without it.

Most helpful comment

Got it. I was missing if (!$request->ajax()) in my custom controller to ignore the validation call.

All 4 comments

Sounds like we have some JS that might need "PreventDefault".... @tnylea, it sounds like a JS change, mind seeing if you can track it down?

First request is a checking your form has a validation errors, if has you will get a message with your fields errors(first request), if doesn't have errors form is unbind from submit and submiting form without errors to controller(second request). This is not saving twice your bread, just first request is checking for your form has validations errors.

Got it. I was missing if (!$request->ajax()) in my custom controller to ignore the validation call.

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wislem picture wislem  路  3Comments

popica80 picture popica80  路  3Comments

MikadoInfo picture MikadoInfo  路  3Comments

iwasherefirst2 picture iwasherefirst2  路  3Comments

rayqiri picture rayqiri  路  3Comments