Synchronous requests are not working with FF3 RC3

UNCONFIRMED
Unassigned

Status

()

Core
DOM
--
major
UNCONFIRMED
10 years ago
9 years ago

People

(Reporter: manohar, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

10 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0

Recently i upgraded to FF3 RC3, and i found out that synchronous ajax request is not working in the latest build. I have the sample code but i am not able to find how to attach that here :( i am new to this. I am sure that you can easily reproduce this with a small sample which is sending synchronous request. the onreadystatechane is not firing. is this related to old 1.x bug?
waiting for your reply..
its very urgent.
Manohar.s



Reproducible: Always

Steps to Reproduce:
1.write a sample js file which sends a synchronous request.
2.on recieving the response, just alert, 
3.onreadystatechange never fires :(
Actual Results:  
onreadystatechage never fires

Expected Results:  
onreadystatechage should fire
You can attach a testcase using the "add an attachment" link.
Component: General → DOM
Product: Firefox → Core
QA Contact: general → general
(Reporter)

Comment 2

10 years ago
Created attachment 325221 [details]
The attachment has a php, js and html file. on typing a letter it sends a request to fetch related names. i am using synchronous request.
(Reporter)

Comment 3

10 years ago
Comment on attachment 325221 [details]
The attachment has a php, js and html file. on typing a letter it sends a request to fetch related names. i am using synchronous request. 

/* here is HTML file*/
<html>
<head>
<script src="clienthint.js"></script> 
</head>
<body>

<form> 
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>

<p>Suggestions: <span id="txtHint"></span></p> 

</body>
</html>
/* here is PHP file*/
<?php
header("Cache-Control: no-cache, must-revalidate");
 // Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Cinderella";
$a[]="Diana";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";

//get the q parameter from URL
$q=$_GET["q"];

//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
  $hint="";
  for($i=0; $i<count($a); $i++)
  {
  if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    {
    if ($hint=="")
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint." , ".$a[$i];
      }
    }
  }
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>


/*here is JS file sending synchronous request*/

var xmlHttp

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

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;
}
Attachment #325221 - Attachment filename: ajax.zip → ajax
I get only in Internet Explorer a suggestion: 
Suggestions: 0 if (strlen($q) > 0) { $hint=""; for($i=0; $i
(Reporter)

Comment 5

10 years ago
you need to give "http://..." ok in IE on typing you are getting some response atleast right? r u getting similar response in FF3?
(Reporter)

Comment 6

10 years ago
you need to give "http://..." ok in IE on typing you are getting some response atleast right? r u getting similar response in FF3?

Comment 7

10 years ago
Problem still exists in Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 (latest release on Dec. 23 2008)

Tested the code below on all other major browsers (IE, Opera, Safari, Chrome) as well, problem only found in FF.

Code to reproduce:

<!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" lang="en-US" xml:lang="en-US">
<head>
<title>Firefox XMLHttpRequest bug</title>
<script type="text/javascript">

function bugdemo () {
  var xmlHttp;

  try { xmlHttp=new XMLHttpRequest(); }
  catch (e) {
    try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
      try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange = function () {
    document.getElementById("state").innerHTML = xmlHttp.readyState;
  }

  // onreadystatechange is NOT called with synchronous open
  // onreadystatechange IS called with async open
  xmlHttp.open ("GET", "bogus.pl", false);

  xmlHttp.send (null);
}

</script>
</head>
<body onload="bugdemo ()">
<p id="state">state</p>
</body>
</html>

Comment 8

9 years ago
on https://developer.mozilla.org/en/XMLHttpRequest there is a warning that onreadystate should not be used in synchronous case. So probably this is intentional

Comment 9

9 years ago
Good point, and using onreadystatechange is totally unneccessary with synchronous open anyway; you can just put the code to deal with the loaded data right after the send call (as compared with my example code):

  xmlHttp.open ("GET", "bogus.pl", false);
  xmlHttp.send (null);
  document.getElementById("state").innerHTML = xmlHttp.readyState;

My main issue with this behaviour of FF though, is that it's not consistent with the other major browsers. If FF is the only 'purist', while the other browsers allow the frowned-upon code, FF will be blamed for compatibility issues.
You need to log in before you can comment on or make changes to this bug.