Ver Mensaje Individual
  #7 (permalink)  
Antiguo 09/01/2012, 14:34
Requenaeo
 
Fecha de Ingreso: marzo-2011
Ubicación: Punta de Mata
Mensajes: 106
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: Actualizar PHP+AJAX

hola ahora neceto su ayuda aqui esta un codigo que revise y probe y reacciona perfctamente pero solo fncia con un archov de texteo y quiero que reaccione con uno de php aqui estanm los codigo:

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. var Comet = Class.create();
  3. Comet.prototype = {
  4.  
  5.   timestamp: 0,
  6.   url: 'backend.php',
  7.   noerror: true,
  8.  
  9.   initialize: function() { },
  10.  
  11.   connect: function()
  12.   {
  13.     this.ajax = new Ajax.Request(this.url, {
  14.       method: 'get',
  15.       parameters: { 'timestamp' : this.timestamp },
  16.       onSuccess: function(transport) {
  17.         // handle the server response
  18.         var response = transport.responseText.evalJSON();
  19.         this.comet.timestamp = response['timestamp'];
  20.         this.comet.handleResponse(response);
  21.         this.comet.noerror = true;
  22.       },
  23.       onComplete: function(transport) {
  24.         // send a new ajax request when this request is finished
  25.         if (!this.comet.noerror)
  26.           // if a connection problem occurs, try to reconnect each 5 seconds
  27.           setTimeout(function(){ comet.connect() }, 5000);
  28.         else
  29.           this.comet.connect();
  30.         this.comet.noerror = false;
  31.       }
  32.     });
  33.     this.ajax.comet = this;
  34.   },
  35.  
  36.   disconnect: function()
  37.   {
  38.   },
  39.  
  40.   handleResponse: function(response)
  41.   {
  42.     $('content').innerHTML += '<div>' + response['msg'] + '</div>';
  43.   },
  44.  
  45.   doRequest: function(request)
  46.   {
  47.     new Ajax.Request(this.url, {
  48.       method: 'get',
  49.       parameters: { 'msg' : request }
  50.     });
  51.   }
  52. }
  53. var comet = new Comet();
  54. comet.connect();
  55. </script>
aqui esta el php llamada backend.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. $filename  = dirname(__FILE__).'/data.txt';
  4.  
  5. // store new message in the file
  6. $msg = isset($_GET['msg']) ? $_GET['msg'] : '';
  7. if ($msg != '')
  8. {
  9.   file_put_contents($filename,$msg);
  10.   die();
  11. }
  12.  
  13. // infinite loop until the data file is not modified
  14. $lastmodif    = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;
  15. $currentmodif = filemtime($filename);
  16. while ($currentmodif <= $lastmodif) // check if the data file has been modified
  17. {
  18.   usleep(10000); // sleep 10ms to unload the CPU
  19.   $currentmodif = filemtime($filename);
  20. }
  21.  
  22. // return a json array
  23. $response = array();
  24. $response['msg']       = file_get_contents($filename);
  25. $response['timestamp'] = $currentmodif;
  26. echo json_encode($response);
  27.  
  28. ?>
ahora no se y e intentado pero no da resultado por favor ayudenme!!