简体   繁体   中英

Why does this javascript code prevent my browser from ever loading?

I'm learning javascript and jquery and have written a very basic script inside my file. I'm experiencing two problems...

  1. The browser never finishes loading the document, it just sits there with the loading icon animating in the tab. Any ideas?
  2. I can't seem to debug this using firebug. When I set a breakpoint anywhere in the document load function, it never hits. Any ideas?

Here's my code...

<html>
<head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link media="screen" type="text/css" href="default.css" rel="stylesheet">       
    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
    $(function()
    {
        var strMarkup = "";
        var strXMLFile = "";

        //Parse XML and generate accordion elements
        var arrayAccordianElements = ParseXML(strXMLFile);

    }); 

    function ParseXML(strPath)
    {
        var arrayEvents = new Array();
        arrayEvents[0] = "test1";
        arrayEvents[1] = "test2";
        arrayEvents[2] = "test3";

        //Return the accordian elements
        return arrayEvents;
    }       
    </script>
</head>
<body>
    hello
</body>
</html>

As you experts can see, my webpage should simply display "hello" after processing some javascript that creates an array inside of a function. Do you see any problems? I apologize if they're obvious problems, I'm a noob :)

Thanks in advance for all your help!

Code-wise I don't see anything that would cause an infinite loop at all. However, knowing firefox etc, there may be a variety of things out of your control. Start with restarting the browser. Profile the script with Firebug (Console > Profile > Reload the page > Press profile again), and see what part takes most time.

One thing, probably unrelated, close your link tag. is sufficient.

Runs fine for me in Safari 4.0.3. Make sure your path to jQuery is correct? If it is incorrect and there's something misconfigured and jQuery fails to load, that will hang indefinitely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM