Jump to content

Ajax:( Please help me


rashmi_k28

Recommended Posts

This is a file called test.php which is calling the file time_test.php.

 

 

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP + Ajax auto refresh DIV</title>
<script>
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 mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;




var i=0;
var ii = 0;
function ajax_update()
{

        url = "time_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()',300);
}

</script>

<body onload="ajax_update();">
<div id="content">Loading<div>

</body>

</html>

 

 

time_test.php

 

$tim=time();
print_r($tim);

 

 

 

1) Can I include time_test.php with test.php and make it a single file instead of 2 different file.

 

How to change the ajax script if the time_test.php is also inclded in the same file??

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.