Problem with cors

1 reply · opened Aug 7, 2023

DdatrikAug 7, 2023

While developing a web with a payment system, using Stripe + Django, I am facing a CORS problem. I'm trying to create a session through a CANVAS form with your plugin, but it seems like functions.js and ajaxForm is catching the request and changing the headers.

I tried in localhost, with my own nginx, in my server side with its own nginx, adding django-cors-headers, using Access-Control-Allow-Origin = * and nothing works.

Do you know where it can be the error? I cannot locate it, just the files plugins.js and functions.js, related with ajaxForm, but cannot find the exact line that is breaking the requests.

SSemicolon WebSTAFFAug 8, 2023

Hello,

Apologies for the inconveniences caused!

Canvas Template does not modify the Headers in any way and CORs issues occur either on Local File Systems or Server misconfigurations, so we can assure you that it is not related to Canvas' Codes. We would recommend integrating everything without AJAX first, by disabling it adding the .customjs Class to the .form-widget DIV. Then when using AJAX, make sure that the PHP File returns the Success/Error Message in a JSON Format. Example for Success:
[ch_pre type="php"]echo '{ "alert": "success", "message": "Payment Successful!" }';
exit;[/ch_pre]

or Error:
[ch_pre type="php"]echo '{ "alert": "error", "message": "Payment Unsuccessful!" }';
exit;[/ch_pre]

There are no other changes or settings required and this should work by default. For more control over Alerts, you can consider checking this Documentation: https://docs.semicolonweb.com/docs/forms/alerts/ .

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard