Hi,
I have a simple code which works well in I.E ,but it is not working in mozilla firefox 3.0..Why is it so.
the code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
         <html xmlns="http://www.w3.org/1999/xhtml">
   
     <head>
   
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>Ajax - PHP example</title>
   
      </head>
   
       <body>
  
     <script language="javascript" type="text/javascript">
  
      <!--
  
      // Get the HTTP Object
  
      function getHTTPObject(){
  
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  
      else if (window.XMLHttpRequest) return new XMLHttpRequest();
  
      else {
  
      alert("Your browser does not support AJAX.");
  
      return null;
  
      }
  
      }
  
      // Change the value of the outputText field
  
      function setOutput(){
  
      if(httpObject.readyState == 4){
        
     document.getElementById('outputText').value = httpObject.responseText;
         
      }
  
      }
  
   
        function doWork(){
  
      httpObject = getHTTPObject();
  
      if (httpObject != null) {
  
      httpObject.open("GET", "http://10.10.2.46:4001/upperCase.php?inputText="
  
      +document.getElementById('inputText').value, true);
  
      httpObject.send(null);
  
      httpObject.onreadystatechange = setOutput;
  
      }
  
      }
  
    var httpObject = null;
  
     //-->
  
      </script>
  
     <form name="testForm">
  
      Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />
  
      Output text: <input type="text" name="outputText" id="outputText" />
  
      </form>
  
      </body>
  
      </html>

Php:

<?php
  
      if (isset($_GET['inputText']))

      echo strtoupper($_GET['inputText']);

      ?>

I've done a Lite modification in your code, the getHTTPObject() function has been removed on.

var httpObject, url;

function setOutput() {
   if ( httpObject.readyState == 4 ) {
      document.getElementById("outputTex").value = httpObject.responseText;
   } else { alert("Failed to load data " + httpObject.statusText);
     }
}

function doWork()
{
     url = "http://10.10.2.46:4001/upperCase.php?inputText" + document.getElementById("inputText").value; 
   httpObject = null;
   httpObject = ( window.ActiveXObject ) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
   if ( httpObject !== null ) { httpObject.onreadystatechange = setOutput;
      httpObject.open("GET", url, true);
      httpObject.send( null );
  } else { alert("Your browser does not support AJAX!"); 
  }
}

Thank you for you reply.The problem is if i give just"uppercase.php" as the url then it is giving the status code.But if i give the server path http://10.10.2.46:4001/upperCase.php?inputText" as url it is not even going inside the setoutput() function.This problem is only in mozilla.Could you tell me why is it so.

From line #15 insert this before sending out request, like this:

if ( httpObject !== null ) { 
httpObject.setRequestHeader("Content-Type", "application-x-www-form-urlencoded");
httpObject.onreadystatechange = setOutput;
// and so on... All the following code must reamain as-is.

From line #15 insert this before sending out request, like this:

if ( httpObject !== null ) { 
httpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpObject.onreadystatechange = setOutput;
// and so on... All the following code must reamain as-is.

I did the same.If i include the setheader line it is showing some errorrs.
thanks..

If that aint workin then you'll have to remove that block. Now let's head back to the issue. From line 14 after the declaration of the XMLHttpRequest object &#8212; add this line:

httpObject = ( httpObject.overrideMimeType ) ? httpObject.overrideMimeType("text/xml") : httpObject;

hope this will catch the issue, GOOD day...

If that aint workin then you'll have to remove that block. Now let's head back to the issue. From line 14 after the declaration of the XMLHttpRequest object — add this line:

httpObject = ( httpObject.overrideMimeType ) ? httpObject.overrideMimeType("text/xml") : httpObject;

hope this will catch the issue, GOOD day...

Even that didnt work out.Any way thank you so much for your reply.Hope there will be some solution for it.

The line httpObject.overrideMimeType("text/xml"); above will cause JavaScript Console errors in firefox 1.5 or later as documented here

This article has been dead for over six months. Start a new discussion instead.