/
Enable CORS support in FormManager
Enable CORS support in FormManager
The FormManager JavaScript class is used to submit & validate forms via AJAX without full page reload. However in case, when we're located in a non-secure page (on http:// url) and want to AJAX-submit form to secure page (on https://) we're getting CORS error, because to JavaScript change in protocol is already considered as cross-domain request.
To avoid this we need to:
- set
crossDomain: false
in the options of any ajax request that FormManager does - just send headers below and exit in case if
$_SERVER['REQUEST_METHOD'] == 'OPTIONS'
- send following headers before outputting content to a browser:
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
We have 2 problems with header sending:
- if we send them in
kApplication:Done
method, then the events, that don't parse template won't get them - if we send them in event processing code then with no event in url the template won't get them
- if we set in both places then we get double amount of headers when both template & event are present
What we miss in the application is the ability for centrally specify what headers needs to be sent (possible with override from event/template) before content is displayed.