javascript - Using AJAX/PHP/JS to report multiple status messages during a long process -


i understand using php isn't possible send messages dom using ajax entire script must execute before response becomes available. such, appears have 2 options:

  1. split long process several smaller ones , report after each
  2. write status updates file , have system read file process executes.

are there big advantages or disadvantages either method?

i haven't understood methods questioning, here (using jquery , php):

in javascript, use window.settimeout(), call function uses ajax callback check url.

url php script, checks if new message present or not.

php script checks new message either in flat tile or in db, not sure use.

script prints message, either in straight html markup, or simple text, or in json or xml format.

on success, ajax call, outputs response selector on page, , calls again window.settimeout().

this part of html markup:

<div id="systemmessage">here goes new message</div> 

this part of javascript:

$(document).ready(function(){  window.settimeout('checkformessages()',5000); //sets 5 seconds. });  function checkformessages(){ $.ajax(function(){  url: "checkformessages.php",  success: function(data){   if(data!=''){     $('#systemmessage').html(data); //place response in systemmessage   }    window.settimeout('checkformessages()',5000); //we set timeout again  } });  } 

this part of php script called i.e. "checkformessages.php":

$message = file_get_contents('messages.txt'); //check file output new message  //or $message='';  //use db table, fields id (int autoincrement, primary), message(text), user_id (integer), created(integer, strtotime - timestamp)   $sql = 'select * system_messages user_id=somenumber , created>(current time - 5 seconds)'; //this more pseudo code, correct syntax  $result = mysql_query($sql); if(mysql_num_rows($result)>0){  while($row = mysql_fetch_object($result)){   $message.= $row->message.' <br/>'; } }            if($message  && $message!=''){     echo $messages;      } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -