By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

ajax in firefox..

P: 5
Hi i have a simple code which is working in I.E but not working in firefox.I have given the code here.. Thankyou..
javascript:

Expand|Select|Wrap|Line Numbers
  1.       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.  
  3.       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.          <html xmlns="http://www.w3.org/1999/xhtml">
  5.  
  6.      <head>
  7.  
  8.       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9.          <title>Ajax - PHP example</title>
  10.  
  11.       </head>
  12.  
  13.       <body>
  14.  
  15.       <script language="javascript" type="text/javascript">
  16.  
  17.       <!--
  18.  
  19.       // Get the HTTP Object
  20.  
  21.       function getHTTPObject(){
  22.  
  23.       if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  24.  
  25.       else if (window.XMLHttpRequest) return new XMLHttpRequest();
  26.  
  27.       else {
  28.  
  29.       alert("Your browser does not support AJAX.");
  30.  
  31.       return null;
  32.  
  33.       }
  34.  
  35.       }
  36.  
  37.       // Change the value of the outputText field
  38.  
  39.       function setOutput(){
  40.  
  41.       if(httpObject.readyState == 4){
  42.  
  43.      document.getElementById('outputText').value = httpObject.responseText;
  44.  
  45.       }      
  46.  
  47.       }
  48.  
  49.       // Implement business logic
  50.         function doWork(){
  51.  
  52.       httpObject = getHTTPObject();
  53.  
  54.       if (httpObject != null) {
  55.  
  56.       httpObject.open("GET", "upperCase.php?inputText="
  57.  
  58.       +document.getElementById('inputText').value, true);
  59.  
  60.       httpObject.send(null);
  61.  
  62.       httpObject.onreadystatechange = setOutput;
  63.  
  64.       }
  65.  
  66.       }
  67.  
  68.       var httpObject = null;
  69.  
  70.       //-->
  71.  
  72.       </script>
  73.  
  74.       <form name="testForm">
  75.  
  76.       Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />
  77.  
  78.       Output text: <input type="text" name="outputText" id="outputText" />
  79.  
  80.       </form>
  81.  
  82.       </body>
  83.  
  84.       </html>
Php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.       if (isset($_GET['inputText']))
  4.  
  5.       echo strtoupper($_GET['inputText']);
  6.  
  7.       ?>
Apr 2 '09 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
Put the onreadystatechange line before open().
Apr 2 '09 #2

P: 5
Thank you for your reply but is not working in firefox 3.It is working in explorer
Apr 2 '09 #3

acoder
Expert Mod 15k+
P: 16,027
I just tested your original posted code in FF3 and it worked absolutely fine. Are you sure you haven't got any other code?
Apr 2 '09 #4

P: 5
I think there is something wrong with the server.Is there anything i need to enable for php to work.Thank you..
Apr 2 '09 #5

acoder
Expert Mod 15k+
P: 16,027
But if it's working in IE, maybe it's not. To confirm whether it is, test the PHP file directly without using Ajax.
Apr 2 '09 #6

P: 5
sorry to disturb you again.Which version of firefox you tried .i have mozilla firfox 3.0.8
Apr 2 '09 #7

acoder
Expert Mod 15k+
P: 16,027
The same version on Windows.
Apr 2 '09 #8

P: 5
I think the problem is with the url.If i simply give uppercase.php then it is showing the status code. If i give the server path (10.10.2.46:4001/uppercase.php) then it is not even going inside the setoutput function but it is working in internet explorer.could you please tell me what could be the reason.how did you give the path to the server side php.
Thankyou..
Apr 3 '09 #9

acoder
Expert Mod 15k+
P: 16,027
Yes, use a relative path. There's no need to specify the full path.
Apr 3 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.