AJAX code does not always work in IE


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: AJAX code does not always work in IE

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    AJAX code does not always work in IE

    Hi I have a peculiar issue with IE and AJAX. I have a certain script that works fine the data is processed the for the first time but if it is run with the same data it fails to operate. This failure only occurs in IE.

    It is part of the checkout process on our website.
    If you want to see the error in action, please use this URL

    http://www.fuzzycross.com

    You will have to select an item to buy(don't worry about buying something just don't finish the transaction) and go to the shopping cart on that page the area in question is the zip code and sales tax fields as described here.

    Here is a typical situation where I see a failure again only in IE.
    you go to the checkout process and enter a shipping option and a zipcode say 91401; it processes normally. Processing normally means calling a php script that sends a query to a mysql database to get a valid value for calculating a sales tax. In this case becauseit is a California zip code and we are in California it comes back with a value and the tax field in the form is updated.
    If the zip code is not in California it returns with 0 and that is updated in the tax field. such would be the case if 55056 was entered for the zipcode and again it works just fine, the first time.

    If, however, I enter 91401 it comes back and the field is updated. I then change it to 55056 the field changes to zero, again correct, I then change it to 91402 it still process correctly.

    Now when I do this same process again in a different session I start with 91401, it works, I change it to 55056, it still works , I change it back to 91401 and nothing happensi change it again to say 91402 and it works this time if I change it back to 55056; nothing, 91401; nothing, 91402; nothing, but again if I enter 91403 it works and a value is returned.

    Again this is only in IE

    Here is my code for my AJAX calls and the PHP script that processes the database call


    javascript
    Code:
    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;
    		}
    }
    
    
    function doWork5(subtotal){
    	error=0;
    	if( ( (document.cartform.shipping[0].checked)  || (document.cartform.shipping[1].checked) || (document.cartform.shipping[2].checked) ) ==0) {
    		alert("You need to select a shipping option");
    		error=1;
    		}
    
    //	data =parseFloat(document.getElementById('shippingval').value.substr(1));
    	zipdata =document.getElementById('zip').value;
    
    	if (zipdata == '#####') {
    		alert("You need to enter a Zip Code");
    		error=1;
    	}
    	
    	if(error==1) {
    		return;
    	}
    
    //	value=data + parseFloat(subtotal);
    
    	value= parseFloat(subtotal);
    	httpObject5 = getHTTPObject();
    
    
    	if (httpObject5 != null) {
    		httpObject5.open("GET", "istaxable.php?taxabletotal="+value+"&inputText="+zipdata, true);
    		httpObject5.send(null);
    		httpObject5.onreadystatechange = setOutput5;
    	}
    }
    
    function setOutput5(){
    	if(httpObject5.readyState == 4){
    		document.cartform.taxval.value="$" + parseFloat(httpObject5.responseText);
    		grandtotal = parseFloat(httpObject5.responseText) + parseFloat(document.cartform.ordersubtotal.value.substr(1)) + parseFloat(document.cartform.shippingval.value.substr(1));
    		document.cartform.ordertotal.value="$" + grandtotal.toFixed(2);
    	}
    }
    php script
    PHP Code:

    $subtotal
    =$_GET['taxabletotal'];
    $zip=$_GET['inputText'];
    $query1="SELECT distinct STATE_A from us2 WHERE STATE_Z='".$zip."'";
    $result mysql_query($query1)
        or die(
    mysql_error());
    $row mysql_fetch_array($resultMYSQL_BOTH);
    if(
    $row['STATE_A']=="CA") {
        
    $taxval=($subtotal*.0725);
        
    printf("%01.2f"$taxval);
    }
    else {
        if(
    mysql_num_rows($result)==0) {
            echo 
    "";
        }
        else {
            echo
    "0.00";
        }

    Subsequent calls to other functions with the same data after this call is processed are processed correctly.
    No error is ever indicated that I can see.
    In my testing I have added alert statements to verify the data is being sent in correctly and it is.

    It appears to just decide not to process the php script some of the time

    I guess I say thanks to IE for another buggy thing

    Any help or assistance will be greatly appreciated

    thanks
    Jeff

  2. #2
    Join Date
    Jul 2011
    Posts
    2
    The issue has been resolved It was caching the GET call and not processing anything since all data was cached, Resolution was achieved when I added the js date call to the GET call data thus making it different each time and forced to execute.

    Thanks to all who took the time to read

  3. #3
    Join Date
    Dec 2008
    Location
    *****, Nigeria
    Posts
    62
    hi jjanes,

    I too have issues with the way my IE9 renders my ASP.NET pages. It just scatters them accross the screen even after putting themin tables. Can youimagine that? Now I set Mozilla firefox asmy default page. Please how can I uninstall IE 9 and re install it? Thanks.
    Mobile: +234 706 042 6036
    Email: charles@hedonmark.com
    Website: www.hedonmark.com

    “To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.”
    —Ralph Waldo Emerson

Similar Threads

  1. Replies: 0
    Last Post: 05-19-2007, 03:04 PM
  2. Replies: 0
    Last Post: 05-02-2006, 04:37 AM
  3. Replies: 1
    Last Post: 08-25-2005, 11:19 PM
  4. Make VB code work in MS Access 2000?
    By Pihlis in forum VB Classic
    Replies: 2
    Last Post: 07-17-2002, 12:34 AM
  5. Code security
    By Rob Teixeira in forum .NET
    Replies: 5
    Last Post: 11-27-2001, 06:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center