Dynamic data exchange between JavaScript and PHP

This is a discussion on Dynamic data exchange between JavaScript and PHP within the PHP Language forums, part of the PHP Programming Forums category; Hi. I was thinking about how to dynamically submit and recieve Data between Javascript and PHP. After some days of ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-07-2006
Gulasch
 
Posts: n/a
Default Dynamic data exchange between JavaScript and PHP

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(content)
{
var s=document.createElement("script");
s.src="recieve.php?content="+content;
document.getElementById("body").appendChild(s);
}
function recieve_data(content)
{
if (content) alert("OK");
else alert("ERROR");
}
</script>
</head>
<body id='body'>
Sometext
<input type=button OnClick='send_data("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
Reply With Quote
  #2 (permalink)  
Old 07-07-2006
Robin
 
Posts: n/a
Default Re: Dynamic data exchange between JavaScript and PHP

Gulasch wrote:
> 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--


See: http://www.dhtmlcentral.com/tutorial...ials.asp?id=11

Same idea but removes old script elements.

Robin
Reply With Quote
  #3 (permalink)  
Old 07-11-2006
Mel
 
Posts: n/a
Default Re: Dynamic data exchange between JavaScript and PHP

On 2006-07-07 19:23:33 +1000, Gulasch <pgrassl@gmx.at> said:

> 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(content)
> {
> var s=document.createElement("script");
> s.src="recieve.php?content="+content;
> document.getElementById("body").appendChild(s);
> }
> function recieve_data(content)
> {
> if (content) alert("OK");
> else alert("ERROR");
> }
> </script>
> </head>
> <body id='body'>
> Sometext
> <input type=button OnClick='send_data("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


Use the Javascript XHR object (or a library like Prototype which will
abstract it for you).
http://www.sergiopereira.com/article...ingAjaxRequest

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:01 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0