CORS Error after submitting form with jQuery -- caused by nicepage.js

jonsnow
3 Posts
jonsnow posted this 15 April 2020
Report a bug

Hey,

your JavaScript-file "nicepage.js" prevents my form to be submitted to Paypal without a CORS ERROR.
When I remove the nicepage.js script, everything works fine.

  • What I'm doing:

I use jQuery serialize and then $.post to submit the form-data to my server, before submitting the form to PayPal.

Of course PayPal doesn't allow Ajax-requests from other origins and this is why I am submitting the form normally by jQuerys .submit()

This is normally a good way to submit payments to PayPal.
But however the Nicepage-javascript messes this up... what is the solution to this?

Thanks Elias

By the way:
first impression of error:
jQuery 1.91 is now 7 years old... would you mind to update the version? I would like to use an more up to date version (3.41 or newer)

Hey, your JavaScript-file "nicepage.js" prevents my form to be submitted to Paypal without a CORS ERROR. When I remove the nicepage.js script, everything works fine. - What I'm doing: I use jQuery serialize and then $.post to submit the form-data to my server, before submitting the form to PayPal. Of course PayPal doesn't allow Ajax-requests from other origins and this is why I am submitting the form normally by jQuerys .submit() This is normally a good way to submit payments to PayPal. But however the Nicepage-javascript messes this up... what is the solution to this? Thanks Elias By the way: first impression of error: jQuery 1.91 is now 7 years old... would you mind to update the version? I would like to use an more up to date version (3.41 or newer)
Vote to pay developers attention to this features or issue.
4 Replies
Order By: Standard | Newest
jonsnow
3 Posts
jonsnow posted this 16 April 2020

By looking at your Javascript file (nicepage.js) I now understand the problem:

this (8 year old script) is preventing every kind of submit by using jQuery:

  1. preventDefault
  2. stopPropagation

then serializing the form and trying to send the data with Ajax.

8 Years ago CORS policy wasn't an issue, but in the meanwhile all browsers follow it and it's not a good practice anymore to submit form data to a foreign server (where you cannot control the headers!) by sending them by Ajax and not by submitting the form.
Of course this can also be done by jQuery Ajax, but the big advantage of using jQuery submit is, that you won't have CORS issues with that, because for the server it's not an automated request, but a human sent form.

However the problem (that nicepage.js is controlling all forms) can be bypassed by renaming the form and inputs, I and creating the form completely without the nicepage-desing, I guess?

Or do I have to edit nicepage.js myself? Maybe this would be a good idea, because I could update it to work with jQuery 3.5 at the same time.

**By looking at your Javascript file (nicepage.js) I now understand the problem:** this (8 year old script) is preventing every kind of submit by using jQuery: 1. preventDefault 2. stopPropagation then serializing the form and trying to send the data with Ajax. 8 Years ago CORS policy wasn't an issue, but in the meanwhile all browsers follow it and it's not a good practice anymore to submit form data to a foreign server (where you cannot control the headers!) by sending them by Ajax and not by submitting the form. Of course this can also be done by jQuery Ajax, but the big advantage of using jQuery submit is, that you won't have CORS issues with that, because for the server it's not an automated request, but a human sent form. However the problem (that nicepage.js is controlling all forms) can be bypassed by renaming the form and inputs, I and creating the form completely without the nicepage-desing, I guess? Or do I have to edit nicepage.js myself? Maybe this would be a good idea, because I could update it to work with jQuery 3.5 at the same time.

Last edited 16 April 2020 by jonsnow

jonsnow
3 Posts
jonsnow posted this 17 April 2020

I solved the issue by removing the directives from the form, which have been included into the form by nicepage automatically when I edited the form with nicepage.

I solved the issue by removing the directives from the form, which have been included into the form by nicepage automatically when I edited the form with nicepage.
julie.legrand9420
1 Posts
julie.legrand9420 posted this 18 August 2020

Hey can you please tell me which directives exactly did you remove

Hey can you please tell me which directives exactly did you remove
IsaacTheDev
9 Posts
IsaacTheDev posted this 18 August 2020

I solved the issue by removing the directives from the form, which have been included into the form by Nicepage automatically when I edited the form with Nicepage.

Yeah, are you able to send us the fixed nicepage.js file without the form submit function? It's pretty annoying, I had to rewrite the form output source to itself so it doesn't use extra data and I still can't figure out the JavaScript file.

> I solved the issue by removing the directives from the form, which have been included into the form by Nicepage automatically when I edited the form with Nicepage. Yeah, are you able to send us the fixed `nicepage.js` file without the form submit function? It's pretty annoying, I had to rewrite the form output source to itself so it doesn't use extra data and I still can't figure out the JavaScript file.
You must log in or register to leave comments