Mobile app version of vmapp.org
Login or Join
Sent6035632

: How to make client side and server side communicate? I have apache installed, and I would like (using php/and or javascript, html) to do the following but I do not know how. To send my client

@Sent6035632

Posted in: #Apache #Browsers #Server

I have apache installed, and I would like (using php/and or javascript, html) to do the following but I do not know how.


To send my client to the server a value x
The server to increase x by one and to send it to client
Client divides it by two and sends it to server
server send the h((x+1)/2) back to client


How I can do that?... I am confused as I do not know how to make a server and a browser to communicate. |However, I do not thing that it is very difficult...

Thanks in advance

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

2 Comments

Sorted by latest first Latest Oldest Best

 

@Harper822

You would like to use Ajax. I would recommend you use some kind of javascript library to handle the ajax calls.


"With Ajax, web applications can send data to and retrieve data from a
server."


Here is a sample.

Javascript (jquery)

var x, divided, result;
x = 6;

divided = $.ajax({
type: "GET",
url: "serverside.php?x=" + x,
cache: false,
async: false
}).responseText;

divided = divided / 2;

result = $.ajax({
type: "GET",
url: "serverside.php?laststage=" + divided,
cache: false,
async: false
}).responseText;

alert(result);


PHP

<?php
if (isset($_GET['x'])) {
$x = $_GET['x'];
$x++;
echo $x;
}

if (isset($_GET['laststage'])) {
echo $_GET['laststage'];
}

10% popularity Vote Up Vote Down


 

@Megan663

Here is a very simple PHP script to get you started:

<?php
if($_GET['v']){
echo intval($_GET['v'])+1;
}
?>

<form>
Enter a value: <input type=text name=v>
<input type=submit>
</form>


I saved that as test.php in my www documents folder. The I opened it as localhost/test.php and was able to submit a number and verify that the script added 1 to it and showed me the result.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme