SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript and Safari

    I've been developing my latest site in Firefox using Firebug to debug my javascript. The main page only shows a loading image which is quickly replaced by an ajax call to the database. Everything seemed to be working fine until I decided to open up Safari just for kicks to take a peek. Well Safari doesn't seem to run the script. It isn't just when the script is called at onload that it doesn't run, I have also set up a form on the left that calls the script every time something is changed, and this doesn't work either so it must be a problem with the script.

    The thing is that I don't have any way to debug it in Safari (like I can with Firebug in Firefox) so I don't have a clue why the script isn't running in Safari (especially since it runs fine in Firefox). Could it be a problem with the XMLHttpRequest? I seem to remember it working earlier in the development of the script so something tells me it is an error in the script. Could somebody take a look and see if they can spot anything or at least give me some tips for debugging in Safari.

    The page is at http://purusstudios.com/oschedule . The ajax functions are located at http://purusstudios.com/oschedule/in...axfunctions.js and the javascript script is located at http://purusstudios.com/oschedule/in...updateTable.js .

    Thanks.

  2. #2
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's looks like it's an OS problem not Safari, it doesn't work in Firefox on my Mac either.

    Also, the code for the AJAX functions, the way you create the HttpRequest looks a bit different to what I would expect to see but I'm no expert

    Here an extract from one of the books I have to hand, maybe it will help:-

    Code:
    <script type="text/javascript">
    var xmlHttp;
    
    function createXMLHttpRequest() {
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        else if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
    }
        
    function startRequest() {
        createXMLHttpRequest();
        xmlHttp.onreadystatechange = handleStateChange;
        xmlHttp.open("GET", "simpleResponse.xml", true);
        xmlHttp.send(null);
    }
        
    function handleStateChange() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
                alert("The server replied with: " + xmlHttp.responseText);
            }
        }
    }
    </script>

  3. #3
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am on Mac OSX 10.4.8 and it works fine for me with Firefox 2.0. Which version of Firefox are you using? I'll take another look at the XMLHttpRequest function, but I am pretty sure it is something to do with the script.

    I finally stumbled across a means of debugging javascript in Safari. Apparently it is already built in, you just need an application to enable it. The debugger is giving me the following errors:

    SyntaxError - Parse error
    includes/js/updateTable.js - Line: 110
    (Line 110 states: var long = document.getElementById('long').checked; )

    Object (result of expression updateCountry) does not allow calls.
    index.php - Line: 1
    (Line 1 is simply the Doctype declaration so I am a bit confused)

    I have to admit I am a bit confused by these two errors :?

  4. #4
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the same vrsn. of OS but my Firefox is 1.5.0.9, my Safari is 2.0.4.

    As for the error, I'm not sure tbh, just double check what's getting passed. Trim back some of the options in updateCountry and test it till it breaks

  5. #5
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I did some testing and taking out the following two lines seems to allow the script to at least run in Safari:

    var long = document.getElementById('long').checked;
    url += "&long=" + escape(long);

    Those two lines are identical to several others in the script except the word 'long' would be something else in the other lines. What is it about those two lines that is stopping the script from running in Safari?

  6. #6
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, and if I simply change the variable 'long' to 'something', it works. Is the word 'long' reserved in javascript in Safari?

  7. #7
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The word "long" is reserved for ECMA extensions in all JavaScript, not just Safari.


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
  •