Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2006, 11:11 AM
Registered User
 
Join Date: Jun 2006
Location: , , Greece.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with AJAX in Firefox

In IE it looks good, but not in Firefox.
Every time I call the info1() or info2() the "Loading..." show up and the content, is placed in the <div id="a"></div>.
This works in both browsers but with a different way.

In IE the previous content in the div is disappeared (this is what I want) and the new one, according to my choice, comes up.

In Firefox the previous content doesn't disappear. It stays on the page and the new one appears below that, and so on....

What's the problem in my code?

I have the folowing code:
<script language="javascript">
var httpRequest;

// for IE
if (window.ActiveXObject)
{
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
// for other browsers
else if (window.XMLHttpRequest)
{
    httpRequest = new XMLHttpRequest();
}

function info1(url)
{
    httpRequest.open('get',url, true);
    httpRequest.onreadystatechange = parseInfo;
    httpRequest.send(null);
}

function info2()
{
    val = document.populate.hidden.value;
    val2 = document.populate.country.options[document.populate.country.selectedIndex].value;
    val3 = document.populate.job.options[document.populate.job.selectedIndex].value;

    httpRequest.open('get','index.php?id=24&action='+v al+'&country='+val2+'&job=' +val3, true);
    httpRequest.onreadystatechange = parseInfo;
    httpRequest.send(null);
}

function parseInfo()
{
    if(httpRequest.readyState == 1)
    {
    document.getElementById('a').innerHTML='Loading... ';
    }
    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
            var answer = httpRequest.responseText;
        document.getElementById('a').innerHTML = answer;
        }
        else
        {
            alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
        }
    }
}
</script>

Any help is appreciated.
Georgia

 
Old June 6th, 2006, 09:37 AM
Registered User
 
Join Date: Jun 2006
Location: , , Greece.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the solution!
So the new parseInfo() function is:

function parseInfo()
{
    if(httpRequest.readyState == 1)
    {
        if (document.getElementById && document.getElementById('a'))
        {
            x = document.getElementById('a');
            x.innerHTML = '<div id="a"></div>';
            x.innerHTML = 'Loading...';
        }
    }
    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
            if (document.getElementById && document.getElementById('a'))
            {
                x = document.getElementById('a');
                x.innerHTML = '<div id="a"></div>';
                x.innerHTML = httpRequest.responseText;
            }
        }
        else
        {
            alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
        }
    }
}

geoko :D

 
Old June 27th, 2009, 11:57 AM
Registered User
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ajax does not work for Firefox has Solution

Here is solution to run ajax code for firefox.

HTML Code:
<script type="text/javascript">
var request; function getName(){
var roll = document.getElementById("roll").value;
var url = "http://localhost:8080/blog_demo/StudentInfo?roll="+roll;
 
if(window.ActiveXObject){
request = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}
 
request.onreadystatechange = showResult;
request.open("POST",url,true);
request.send(null);
}
function showResult(){
if(request.readyState == 4){
if ( request.status == 200 ) {
var response = request.responseXML;
var students = response.getElementsByTagName("Student");
var student = students[0];
 
document.getElementById("NamelH1").innerHTML = student.getElementsByTagName("Name")[0].childNodes[0].data;
document.getElementById("HostelH1").innerHTML = student.getElementsByTagName("Hostel")[0].childNodes[0].data;
document.getElementById("ContactH1").innerHTML = student.getElementsByTagName("Contact")[0].childNodes[0].data;
 
 
}
}
}
</script>
 
http://binodsuman.blogspot.com/2009/...-does-not.html

Thanks,

Binod Suman

http://binodsuman.blogspot.com




Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox vs. IE - Javascript problem VerbatimBOT ASP.NET 2.0 Professional 2 September 25th, 2008 03:28 AM
Ajax error on FireFox when pass value to next page lvb BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 September 28th, 2006 09:22 AM
AJAX in firefox anandham Ajax 0 July 27th, 2006 05:18 AM
firefox problem axeman XSLT 0 November 21st, 2005 10:35 AM
firefox session problem fender79 Classic ASP Professional 0 April 12th, 2005 02:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.