473,656 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ajax using POST - "onreadystatech ange" works in opera but not with firefox???

1 New Member
Hey all,

I've been banging my head against a brick wall on this one for the last 12 hours, and the time has come for me to give up and consult the gurus on this one.

The below URL contains a login page, you can test it using the details
User: marco
Pass: polo

This seems to work PERFECTLY in opera, and it works in firefox but ONLY if I have firebug enabled. I don't care about IE for now, I'll sort that out later.

URL: http://www.doc.ic.ac.uk/project/2006...test/index.htm

The problem lies in the fact that despite the ajax readyState variable evidently changing (as you can see in the debug alert popups), it never executes the code defined by onreadystatecha nge.

If you view in Opera, you'll be able to see that an alert box pops up each time the onreadystatecha nge is triggered.

Can anybody help me? I've consulted google many times and this particular problem doesn't seem to be discussed anywhere.




The source code for my AJAX function:
Expand|Select|Wrap|Line Numbers
  1. function ajaxQuery(uid, pw, action) {
  2.     var desturl = "authd.php";
  3.  
  4.     try {
  5.         // Firefox, Safari, Opera 8.0+
  6.         alert ("DEBUG:\nTrying XMLHttpRequest()");
  7.         ajaxRequest = new XMLHttpRequest();
  8.     } catch (e){
  9.         // Internet Explorer Browsers
  10.         try {
  11.             alert ("DEBUG:\nXMLHttpRequest() failed.\nTrying ActiveXObject(\"Msxml2.XMLHTTP\")");
  12.             ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  13.         } catch (e) {
  14.             try{
  15.                 alert ("DEBUG:\nActiveXObject(\"Msxml2.XMLHTTP\") failed.\nTrying ActiveXObject(\"Microsoft.XMLHTTP\")");
  16.                 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  17.             } catch (e) {
  18.                 alert("Web 2.0 not supported by your web browser.");
  19.                 return false;
  20.             }
  21.         }
  22.     }
  23.  
  24.     ajaxRequest.onreadystatechange = ajaxRequestHandler; // THIS LINE OF CODE IS HATED BY MOZILLA !!!
  25.  
  26.     ajaxRequest.open("POST", desturl, false);
  27.     ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
  28.     ajaxRequest.setRequestHeader("Content-length", 1);
  29.  
  30.     alert("Debugging aJaxQuery() before send():\nreadyState = " + ajaxRequest.readyState);
  31.  
  32.     switch (action) {
  33.         case "auth":     ajaxRequest.send("userID=" + uid + "&password=" + pw + "&action=" + action); break;
  34.         case "reg":     ajaxRequest.send("userID=" + uid + "&password=" + pw + "&action=" + action); break;
  35.         case "accCheck": ajaxRequest.send("userID=" + uid + "&action=" + action); break;
  36.         default: break;
  37.     }
  38.  
  39.     alert("Debugging aJaxQuery() after send():\nreadyState = " + ajaxRequest.readyState);
  40. }
  41.  
  42. function ajaxRequestHandler() {
  43.     alert("Debugging onreadystatechange function():\nreadyState = " + ajaxRequest.readyState);
  44.  
  45.     if (ajaxRequest.readyState == "4") {
  46.         var aResponseT = ajaxRequest.responseText;
  47.         alert("The response should have been: " + aResponseT);
  48.         authResult = aResponseT;
  49.     }
  50. }
Jun 5 '07 #1
5 6404
acoder
16,027 Recognized Expert Moderator MVP
It might have to do with the fact that you're making a synchronous request (make the third argument in the open() method true instead of false).
Jan 29 '08 #2
rook2pawn
2 New Member
Hey, I just ran into this exact same problem as well!


Whenever you need the synchronous request, think about what javascript is "waiting" for it, then make it asynchronous instead, and put the javascript at the end of the attached callback to the onreadystatecha nge ..

I.e. reverse the order and just say NO to synchronous requests.
Jul 17 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Looking back at this, if you have a synchronous request then there's no need for a readystatechang e. It doesn't make sense to call it. When the request is complete, you can assume that the following code would be executed.
Jul 17 '08 #4
rook2pawn
2 New Member
Btw , i came up with an in-between solution for creating fake asynchronous requests without multiple xmlHttpRequest objects. The rational is that multiple global http_request variables is ultimately a bad road to walk (closures, portabilty, one coder has to be aware of another coder's environment, etc)

if ((http_request) && (http_request.r eadyState != 4)) {
setTimeout(func tion(){makePOST Request(url, parameters, callback)}, 100);
return;
}

this goes at the beginning of your makePOSTRequest . Its not recursive since the moment it sets the timeout, it ends the function. Whats nice is now you can get all the benefit of multiple XHR requests, without any additional globals, and without any need for synchronous mode.
Aug 4 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
In effect, this would be similar to making another request in the callback function of the first one. Thanks for posting.
Aug 4 '08 #6

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

Similar topics

10
19158
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I am passing to it. Everything works fine on IE 6. Here's a couple samples of what I am doing: // using GET url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
2
1852
by: Alex | last post by:
Example uploaded to: http://www.clickatus.com/ajax/ BTW - This is for FIREFOX, won't work in IE. I don't know why but when it is executed the browser still in loading state... Even though XMLHttpRequest already got its string from the server... Any help?
2
7107
by: Peter Michaux | last post by:
Hi, I am trying out the Ajax timeout example in Flanagan's book p492. It works fine in Opera but in Firefox the the call to request.abort() doesn't stop onreadystatechange being called. I found some references to this problem in the group archives and on google but no solutions I can seem to implement here. The troublesome code is below. I added what I think are fixes for the IE memory leak probem in two places (which doesn't change...
17
11858
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition show
2
3148
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
1
2074
by: wpt394 | last post by:
I am running a code that works just fine in Firefox, but seems to have trouble in IE. The basic idea is that a travel search process is initiated with one ajax call, and a 2nd ajax call 'updates' the page with the results that have been retrieved thus far. This 2nd call loops until the first call (the search) is complete. Everything works fine in Firefox, but in IE, the 2nd call doesn't work until the very end when the 1st call is complete....
8
2500
by: knkk | last post by:
Instead of an id getting its innerHTML changed, the entire page is getting refreshed with this function of mine (you may want to look just at the end of the function where there's an alert): function morerating(ratingform, checkflag, loc) { var f = document.forms; var rating_done_flag = 0; var params = ""; if (checkflag == true) check = checkrating(ratingform); else
7
4032
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. Before there are six characters entered in the CAPTCHA code field, the 'Send' button is supposed to be disabled. When there are at least six characters in the CAPTCHA code field, the script attempts to verify the CAPTCHA w/AJAX. If it verifies, it...
5
4456
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php script works perfectly and gives me an entire table of correct data. The problem is that when I click...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8498
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.