473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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
Jul 7 '06 #1
2 3291
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
Jul 7 '06 #2
Mel
On 2006-07-07 19:23:33 +1000, Gulasch <pg*****@gmx.atsaid:
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

Jul 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vinay Chopra | last post by:
Hi, Did anybody worked on DDE(Dynamic Data Exchange)? Can someone come with a code piece for implementation of DDE in Microsoft technologies. Thanks, Vinay
2
by: Joakim Braun | last post by:
Greetings, I'm playing around with a web-based interface to MySQL that would let you manage, create and use databases. So far I'm using PHP to talk to MySQL and query strings to exchange the...
1
by: Vinay Chopra | last post by:
Hi, Did anybody worked on DDE(Dynamic Data Exchange)? Can someone come with a code piece for implementation of DDE in Microsoft technologies. Thanks, Vinay
1
by: Jason Chan | last post by:
I have a paging datalist which show a list of thumbnail. Above the datalist there is a dropdown to jump to different paging. On Page_load, I bind the datalist according to the current page. On...
13
by: Krivenok Dmitry | last post by:
Hello all! Perhaps the most important feature of dynamic polymorphism is ability to handle heterogeneous collections of objects. ("C++ Templates: The Complete Guide" by David Vandevoorde and...
38
by: Tom | last post by:
I need my data generating C program on computer #1 to export small amounts of data (one - 40 byte data structure) periodically (once per minute) to a C program on computer #2. I am considering...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
1
by: sutch | last post by:
I have created a DDE( Dynamic-Data Exchange) Client (Console) application to interact with a legacy DDE Server. This client is working perfectly I am asked to develop same functionality in a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.