Hi.
I was thinking about how to dynamically submit and recieve Data between
Javascript and PHP. After some days of trying around I produced the
following piece of code:
--snip--
<html>
<head>
<script>
function send_data(conte nt)
{
var s=document.crea teElement("scri pt");
s.src="recieve. php?content="+c ontent;
document.getEle mentById("body" ).appendChild(s );
}
function recieve_data(co ntent)
{
if (content) alert("OK");
else alert("ERROR");
}
</script>
</head>
<body id='body'>
Sometext
<input type=button OnClick='send_d ata("blabla");' >
</body>
</html>
--snap--
where a button or something else can call the JavaScript-Function
send_data with some data to send to the PHP-Script which can access the
data by using $_GET['content'] and the PHP-Script could output for example
--snip--
recieve_data(1) ;
--snap--
to tell the user, everything went okay.
Well, I've tried it sometimes but I'm still not sure, wheter this is a
regular and "normal" way to let JavaScript and PHP communicate and if
all browsers are able to do what they should do...?
Thanks
Gulasch
I was thinking about how to dynamically submit and recieve Data between
Javascript and PHP. After some days of trying around I produced the
following piece of code:
--snip--
<html>
<head>
<script>
function send_data(conte nt)
{
var s=document.crea teElement("scri pt");
s.src="recieve. php?content="+c ontent;
document.getEle mentById("body" ).appendChild(s );
}
function recieve_data(co ntent)
{
if (content) alert("OK");
else alert("ERROR");
}
</script>
</head>
<body id='body'>
Sometext
<input type=button OnClick='send_d ata("blabla");' >
</body>
</html>
--snap--
where a button or something else can call the JavaScript-Function
send_data with some data to send to the PHP-Script which can access the
data by using $_GET['content'] and the PHP-Script could output for example
--snip--
recieve_data(1) ;
--snap--
to tell the user, everything went okay.
Well, I've tried it sometimes but I'm still not sure, wheter this is a
regular and "normal" way to let JavaScript and PHP communicate and if
all browsers are able to do what they should do...?
Thanks
Gulasch
Comment