rashmi_k28 Posted October 1, 2008 Share Posted October 1, 2008 include("./func.php"); $name = Names(1); array_shift($name); $time_val = $name[0]; array_shift($name); $function2= Centre(1); The function is written in func.php and it is called in a file called test.php How to reload the functions Names(1) and Centre(1) used in the test.php using Ajax so that there is auto refresh each time. var xmlhttp = false ; if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest (); } catch (e) { xmlhttp = false} } function myXMLHttpRequest () { var xmlhttplocal; try { xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")} catch (e) { try { xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")} catch (E) { xmlhttplocal = false; } } if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') { try { var xmlhttplocal = new XMLHttpRequest (); } catch (e) { var xmlhttplocal = false; } } return (xmlhttplocal); } var mnmxmlhttp = Array (); var mnmString = Array (); var mnmPrevColor = Array (); var responsestring = Array (); var myxmlhttp = Array (); var responseString = new String; var i=0; var ii = 0; function ajax_update() { url = "test.php"; target2 = document.getElementById ('content'); ii = i++; var content = "i=" + ii ; mnmxmlhttp = new myXMLHttpRequest (); if (mnmxmlhttp) { mnmxmlhttp.open ("POST", url, true); mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded'); mnmxmlhttp.send (content); errormatch = new RegExp ("^ERROR:"); target2 = document.getElementById ('content'); mnmxmlhttp.onreadystatechange = function () { if (mnmxmlhttp.readyState == 4) { mnmString = mnmxmlhttp.responseText; if (mnmString.match (errormatch)) { mnmString = mnmString.substring (6, mnmString.length); target = document.getElementById ('content'); target2.innerHTML = mnmString; } else { target = document.getElementById ('content'); target2.innerHTML = mnmString; } } } } setTimeout('ajax_update()',500); } When I call this script and use it the page does not get reloaded. Link to comment https://forums.phpfreaks.com/topic/126581-auto-refresh/ Share on other sites More sharing options...
shamuntoha Posted October 5, 2008 Share Posted October 5, 2008 Maybe this way you can do also? per second it call a function. ajax_main(1,2,3,4); /** * @xmlHttp used to detect the browser object * related pages * -------------------------------------------- * Basic standard useing */ var xmlHttp; /** * @ajax_maincall * Call this from your HTML event */ function ajax_maincall(){ // create ajax object ajax_main(2,2,3,4); // Start auto reload ajax_listen(); } /** * @GetXmlHttpObject used to detect the browser and set * xmlHttp * Firefox, Opera , Safari, IE */ function GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } /** * @ajax_main used inside the html action events * Function to be called from the main pages. * ajax_main(option1, option2, option3, option4) * example: * ajax_main( price.options[price.selectedIndex].value + ' ' + this.options[this.selectedIndex].value ); * */ function ajax_main(str1, str2, str3, str4){ // Set xmlHttp object for browser xmlHttp=GetXmlHttpObject(); // Condition for browser if (xmlHttp==null){ alert ("This browser does not support AJAX!"); return; } /* * Variable setup for php or asp or jsp * Prepare your page to return * username ok or password ok */ var url="username_password.php"; url=url+"?username="+str1+"&password="+str2+"&q3="+str3+"&q4="+str4; // Must be used , dont change url=url+"&sid="+Math.random(); /* * Call output event * Query output represent * *condition can be removed */ xmlHttp.onreadystatechange=ajax_output1; // Execute GET method xmlHttp.open("GET",url,true); // Send Get or Post method xmlHttp.send(null); } /** * @ajax_output1 * Login failure * */ function ajax_output1(){ if (xmlHttp.readyState==4){ // Put the html <div id="s1"> $tim = time(); document.getElementById("s1").innerHTML=$tim; } } /** * @ajax_listen time bomb * Timer to ping and pong */ var tImer; function ajax_listen(){ ajax_main(1,2,3,4); cOunter=cOunter+1; tImer=setTimeout("ajax_listen()",1000); } Link to comment https://forums.phpfreaks.com/topic/126581-auto-refresh/#findComment-657744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.