Streaming live at 10am (PST)

Send data from data because of AJAX Block


#1

I try to send a form to and extern payment website. Unfortunately this is not possible because Ajax blocks this. Is it possible to get the values from Webflow to the payment website. If I do this with POST and GET we get an empty array.

The connection we want to make comes from this form: http://earz.webflow.io/pakketten/word-lid-muziekschool


Thanks a lot for getting in touch! At the moment, AJAX will only work for sites that are hosted on the same domain due to CORS restrictions in the browsers.

Basically, AJAX scripting is not allowed for cross-domain scripting to avoid cross-domain scripting attacks.


AJAX for a site hosted in Webflow, works if you embed a page from the same site.

Regarding the domain, if you want to link to the url http://betalen.earz.nl, in order for ajax to work, the domain will need to be hosted in Webflow setup on the hosting tab of site settings.

See more about using a custom domain with your Webflow site here: http://help.webflow.com/faq/how-to-set-up-a-custom-domain-with-your-webflow-site

If you would still like to use ajax with this url but it is an external site, and needs to stay that way, then another option may be to export the site from Webflow and host on your own server, where you can setup special CORS headers for the html pages, to allow for ajax scripts to be executed across domains.

I wish I could tell you that it was a simple matter to put together, but it is a little complex. Here is more info about enabling this kind of ability between different domains: http://techblog.constantcontact.com/software-development/using-cors-for-cross-domain-ajax-requests/


#2

It would be best to put the betalen.earz.nl on the webflow server. But is it possible to put the PHP files on it? I can not do it through the media library.


#3

Hi @martijnrunia,

Posting support email is inappropriate here. Please edit your question.


#4

Hi @martijnrunia, at the moment it is not possible to put the PHP files on the Webflow server as Webflow does not support PHP.

Basically unless the the resource you are trying to load via ajax.load etc is on the same domain, the ajax is going to get blocked by the browser.

Probably the most likely solution is to check the CORS documentation and host the site on your own server, where you would have control on those headers etc.

I hope this helps!


#5

Hey @martijnrunia, You should just implement xdomain because you don't need CORS to get what you want, and I have xdomain working in my webflow instance with no issues whatsoever.

https://github.com/jpillora/xdomain

This worked for me! You include xdomain in your sitewide custom code header like this:

<script src="//cdn.rawgit.com/jpillora/xdomain/0.7.4/dist/xdomain.min.js"></script>

Then you go stick your ajax stuff whereever you want it. And then in your javascript code (i assume either included in your site via custom code or an embedded code block):

//init xdomain (cross domain ajax)
xdomain.debug = false;
xdomain.slaves({
    "http://betalen.earz.nl": "/path/to/proxy.html"
});

You may need to turn on debug to see if you have problems with your configuration until you get it working, in which case it will give you xdomain debug logs on your javascript console in your web browser. Hope this helps anyone who wants to accomplish this.


#6