0

I'm writing a simple application. From C I'm calling ReST API to server.php. In sever.php, once I get the request from C I have to send some Data-X. This Data-X is sent by the javascript when user clicks a button. But I don't know how to get the Data-X from javscript.

        GET
  c    ---->   php                   |  <---       JS
(waits        (handling GET          |       (user clicked button
  for          request &waiting      |          and send data-X
responce)       for Data-X to send)  |             to PHP)

server.php

<?php
    ...
       case 'GET':

           // Wait for JS.
           // Now echo result
           break;
?>

I searched few event listens in php. but I didn't get them. I don't know how to do it. Any help is appreciated.

gangadhars
  • 2,584
  • 7
  • 41
  • 68
  • 1
    Reference: [*HTTP is a stateless protocol.*](http://stackoverflow.com/q/13200152/697154) – Yoshi May 05 '15 at 08:01

2 Answers2

1

It is a bit unclear here where the user is clicking the button. Is the button in the server.php script or somewhere else? But actually it doesn't even matter. Judging by the context you're probably talking about client side JS which only lives in the user's web browser. It's also a bit unclear what you mean by C. Do you mean an application written in the C language?

If all you need to know is that a button has been clicked, you might not even need JS as you can do this with a normal HTML submit button (<input type="submit"> inside a <form>) that send information to PHP (without any JS). If you need to send some other data, where does the data come from so the button knows what to send?

It seems to me that you're calling a PHP script named server.php from some other application (C) using an HTTP GET request to get data from PHP to C, but this connection does not involve client side JS in any way, so server.php needs to have actually gotten the data from JS (or HTML) as a GET or POST request previously and stored the data in a file or some kind of database. Only then PHP can fetch the data and send it to C when C makes the request.

Please try to better explain what you're actually trying to do, so we can help better.

Haprog
  • 793
  • 1
  • 9
  • 21
0

You can get data from GET request with $_GET['var_name'] and POST data with $_POST['var_name'].

Juan de Parras
  • 768
  • 4
  • 18