Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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

Reply With Quote
  #2 (permalink)  
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

Reply With Quote
  #3 (permalink)  
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09:35 AM
firefox session problem fender79 Classic ASP Professional 0 April 12th, 2005 02:51 AM



All times are GMT -4. The time now is 01:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.