vForums Support > Programming & Coding :: Programming Discussion :: > Javascript + PHP

Javascript + PHP - Posted By Aiken (ionfortuna) on 27th Feb 10 at 5:39am
How do I get Javascript to communicate with a PHP file?

I think it is Ajax but I'm not sure how to do it

And how do I get PHP to create/modify txt files to use as basic databases

The answers will help me with an idea I have for one of my forums

Re: Javascript + PHP - Posted By Michael (wrighty) on 27th Feb 10 at 7:55am
Using AJAX is the best way, although it depends what it is that you're trying to do! {Smile}

Re: Javascript + PHP - Posted By Aiken (ionfortuna) on 27th Feb 10 at 9:56am
Basically I want to be able to build a battle system for one of my forums

Re: Javascript + PHP - Posted By Michael (wrighty) on 27th Feb 10 at 10:19am
AJAX can't go cross domain, that's the problem. What do you want this battle system to do? O.o

Re: Javascript + PHP - Posted By Aiken (ionfortuna) on 27th Feb 10 at 10:41am
Battle between 2 users, I thought Ajax could go cross domain

Re: Javascript + PHP - Posted By Michael (wrighty) on 27th Feb 10 at 11:11am
Nope, as far as I know. AJAX can't.

Re: Javascript + PHP - Posted By Aiken (ionfortuna) on 27th Feb 10 at 1:45pm
Than what can I do?

Re: Javascript + PHP - Posted By Ross (admin) on 27th Feb 10 at 2:17pm
 
Than what can I do?


You could use something sometimes referred to as "Poor Mans AJAX" - you can use Javascript to load additional Javascript files to the page.

I don't remember exactly how it works (I think you need some funny onload events to get it working in IE) but the idea is that you create and append a script tag which loads a PHP file on your server, you would pass parameters to this file in it's URL so that it can do something on your server. The file can then return javascript to execute on the page. eg.

var s = document.createElement('script');
s.type = "text/javascript";
s.src = "http://yoursite.com/battle.php?user=admin&action=something&bar=foo";
document.getElementsByTagName('head').item(0).appendChild(s);

Re: Javascript + PHP - Posted By Aiken (ionfortuna) on 27th Feb 10 at 4:07pm
Ah, I see

Re: Javascript + PHP - Posted By indu (indu) on 9th Mar 10 at 9:33am
hai
i dn't know

Re: Javascript + PHP - Posted By dog199200 (dog199200) on 9th Mar 10 at 10:26pm
yea aiken, this was the problem I was having with getting the IM system working {Tongue Out} the Ajax didn't like the cross domain. Though as for your flat file question

you can use php function fileopen with the function fileread and filewrite *I think thats what they are called* you'd have to google how the functions work, but you could also look into setting up a flat file database with PHP, but i can tell you know, it depends on how advanced you want to go, it might be better to just use mysql to store the information then storing it as a fiat file system.

Re: Javascript + PHP - Posted By Marc (cr0w) on 9th Mar 10 at 10:49pm
 
hai
i dn't know


Hello there, welcome to vForums! {Smile}

To introduce yourself to fellow members, please visit the Introductions board.

Please take the time to have a read over our Global Forum Rules & Info to get to know our rules and regulations.

We hope you enjoy your time here! {Smile}

Re: Javascript + PHP - Posted By indu (indu) on 26th Mar 10 at 8:19am
what is html

Re: Javascript + PHP - Posted By indu (indu) on 26th Mar 10 at 8:19am
html is

Re: Javascript + PHP - Posted By Michael (wrighty) on 26th Mar 10 at 9:12am
indu: Please read the PM that I have sent you.

Re: Javascript + PHP - Posted By Aiken (ionfortuna) on 30th Mar 10 at 11:26pm
Posted By dog199200 on 9th Mar 10 at 10:26pm
 
you can use php function fileopen with the function fileread and filewrite *I think thats what they are called* you'd have to google how the functions work, but you could also look into setting up a flat file database with PHP, but i can tell you know, it depends on how advanced you want to go, it might be better to just use mysql to store the information then storing it as a fiat file system.


I am unable to use MySQl in PHP, I have tried many, many times, always failed


Re: Javascript + PHP - Posted By dog199200 (dog199200) on 31st Mar 10 at 1:43am
PM me exactly what you need help with and i'll see what I can do to help you along {Smile} I have been working with PHP and SQL a lot here lately and have become quite adept at it XD