Ajax and PHP?

Get help using Construct 2

Post » Sat Mar 23, 2013 1:56 pm

im trying to make a simple ajax chat room in construct. the problem is that i keep getting an error when i try to send the post data. the php file is on my website and im running the layout in preview. i think the problem is that my browser doesnt allow cross domain post data transfer. how can i test it locally. do i put the php file in the same folder as the
capx file and run my my apache server or do i run the php file on the server and just put in the url im realy stuck guys please help.

Posts: 4
Reputation: 358

Post » Sat Mar 23, 2013 2:01 pm

What I would do is export the project as a "completed" game into wherever your php file is being kept, and then test it that way.

So export the project to C:/xampp/htdocs/phpfilefolder/ or wherever it may be.

Edit: Now you MAY also be able to (haven't tested it) but try to change the "preview server" in the preferences to localhost/foldername with foldername being what your folder is in the htdocs folder, assuming you are using xampp. foldername should be the name you use to connect to your webpage locally.Equinox802013-03-23 14:03:34
Posts: 98
Reputation: 4,734

Post » Sat Mar 23, 2013 2:55 pm

It's a cross domain issue. There is a way around it, but you open yourself up to potential misuse by doing so.

You can setup the headers at the beginning of your php file to allow any domain (or specific domains) to access the php script.

Personally, I setup my ajax call to send a variable called "key" and the script will look for the key variable and if it sees it, it added the header. If it doesn't, it just does things normally so calls from the same domain still work.

Do a Google search for cross domain ajax php header to find out more info on how to set it up. If you still have issues with it, I might be persuaded to write a tutorial like I did for the Highschore table without a plugin via php/ajax that's on my site if I have time this week.
Posts: 210
Reputation: 5,973

Return to How do I....?

Who is online

Users browsing this forum: Eren, gomotion100, mindragon73, PatrikTT, Phoenixbowman, Solomon, Yahoo [Bot] and 6 guests