SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help please! Site AJAX works in IE not in Firefox..

    My site: www.onlyriddles.com

    The problem occurs when I click on the "Answer" button. I should also mention that it worked a few days ago before I move it to a new server.

    Basically it works in IE but it does still show an error indicator at the bottom of the browser. Here's what the error shows when I click on details:
    Line: 53
    Char: 9
    Error: Object doesn't support this property or method
    Code: 0
    URL: http://www.onlyriddles.com
    Of course I'm not sure which file line 53 is contained in.

    In FireFox I just get the "Problem retrieving data - Contact george@onlyriddles.com" alert message (as shown in the script below).

    Here's my javascript.js file:

    Code:
    function get_object(id)
    {
            if (document.getElementById)
            {
                    return document.getElementById(id);
            }
            else if (document.all)
            {
                    return document.all[id];
            }
            else if (document.layers)
            {
                    return document.layers[id];
            }
            else
            {
                    return null;
            }
    }
    
    var xmlhttp;
    var answerid;
    
    function loadXMLDoc(url)
    {
            // code for Mozilla, etc.
            if (window.XMLHttpRequest)
            {
                    xmlhttp=new XMLHttpRequest();
                    xmlhttp.onreadystatechange = xmlhttpChange;
                    xmlhttp.open("POST", url, true);
                    xmlhttp.send(null);
            }
            // code for IE
            else if (window.ActiveXObject)
            {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    if (xmlhttp)
                    {
                            xmlhttp.onreadystatechange = xmlhttpChange;
                            xmlhttp.open("GET", url, true);
                            xmlhttp.send();
                    }
            }
    }
    function Answer (id)
    {
            get_object('answer' + id).innerHTML = 'Loading answer, please wait...';
            loadXMLDoc ('/ajax.php?id=' + id);
            answerid = 'answer' + id;
    
            cooks = get_object('cooks');
            cooksval = cooks.innerHTML;
            get_object('cooks').innerHTML = parseInt(cooksval) + 1;
    }
    
    function Riddles (type)
    {
            get_object('riddles').innerHTML = '';
            loadXMLDoc ('/ajax.php?riddles=' + type);
            answerid = 'riddles';
            get_object('pages').innerHTML = type;
    }
    
    function xmlhttpChange()
    {
            // if xmlhttp shows "loaded"
            if (xmlhttp.readyState==4)
            {
                    // if "OK"
                    if (xmlhttp.status==200)
                    {
                        object = get_object (answerid);
                            object.innerHTML = xmlhttp.responseText;
                    }
                    else
                    {
                            alert("Problem retrieving data - Contact george@onlyriddles.com")
                    }
            }
    }
    Any help is greatly appreciated.
    Last edited by stymiee; May 18, 2006 at 18:12.
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is that one whole file or a single file? If it's a single file, can you splitup the code so we can see where that error might be referring to. Even better if you could show the exact line in the file(s) so we can better get an idea.

  3. #3
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's the whole javascript.js file.

    Here is the part that generates the alert message in FireFox

    function xmlhttpChange()
    {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
    {
    // if "OK"
    if (xmlhttp.status==200)
    {
    object = get_object (answerid);
    object.innerHTML = xmlhttp.responseText;
    }
    else
    {
    alert("Problem retrieving data - Contact george@onlyriddles.com")
    }
    }
    }
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try checking for status code 304 as well (content not changed). I got hit by that one once.

  5. #5
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I am absolutely new to javascript. I have NO idea what you're talking about "check for status code 304"

    You mean add another if statement to check for 304?
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  6. #6
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added a 304 like this and nothing happened or changed

    function xmlhttpChange()
    {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
    {
    // if "OK"
    if (xmlhttp.status==200)
    {
    object = get_object (answerid);
    object.innerHTML = xmlhttp.responseText;
    }

    if (xmlhttp.status==304)
    {
    alert("WE HAVE A 304")
    }
    else
    {
    alert("Problem retrieving data - Contact george@onlyriddles.com")
    }
    }
    }
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  7. #7
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you display the appropriate html alongside the javascript?

  8. #8
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ....... It's at the URL i posted, www.onlyriddles.com
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  9. #9
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh bah, I'm totally blind heh. Alright, I'll take a look and see what I can find.

  10. #10
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright, try putting

    HTML Code:
    alert("xmlhttp type is: " + typeof xmlhttp + " and status is: " + xmlhttp.status);
    before //if "OK". I'm curious to see what it's getting.

  11. #11
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In FireFox it returns this alert:

    xmlhttp type is: object and status is: 406

    In IE it returns this alert:

    xmlhttp type is: object and status is: 200
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  12. #12
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $25 PayPal to whomever can fix this.
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The problem is the following line in the non-IE version of the setup of the request:

    xmlhttp.open("POST", url, true);

    You have IE set to use GET and other browsers to use POST but when you use POST you are not setting up the post fields to be passed with the request (you are passing NULL). 406 is a HTTP error that indicates that the content-type for the request is unknown and is caused by the fact that you don't have a content-type header in your posted request (since you are not posting anything).

    Change the POST reference to GET and it should correct the error.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The solution to this problem is not really that the method needs to be changed to 'GET'. The problem is that using the 'POST' method is very different to using 'GET' when sending data using an XMLHttpRequest.

    Using 'POST' means that the data is not being sent in the url therefore the url would look like this:
    website.com/page.php

    And the 'Content-type' request header needs to be set like this (req is an XMLHttpRequest object):
    req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

    And the data needs to be sent as a parameter of the send method
    req.send('var1=data1&var2=data2');

    Using 'GET' means that the data is being sent in the url therefore the url would look like this:
    website.com/page.php?var1=data1&var2=data2

    And the 'Content-type' request header doesn't need to be set.

    And the data doesn't get sent as a parameter of the send method. Just send null:
    req.send(null);

  15. #15
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    i have some doubts from your code.

    If u answer those, i think i can help you.

    First have you quoted the url in the open method, if the url is defined anywhere it would work and if not it would have asked for the url.

    I guess you provieded as the function xmlhttpChange() is runnning and it would only called if the httprequest is send,

    And in that function the answerid is passed as argument and from where this argument is passed. From your code u have declared that variable and then it would be passed as null value.

    Then pl note that if you have any arguments for the url where you have to send the request, you have to note that as arguments for the send() method else you have to add 'null' as the arguments else it would create problems.

    And i think if you post the html/php code along with this full js code ,

    it would be very easy to identify the proper error.

    Expecting to post the code,

    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •