0

I'm quite new to jQuery and can't find out what doesn't work.

Tn the following sample the code works fine when the page is part of a asp web application.

But when I create a normal Website in IIS the load doesn't work. The event raises (tried it with alert) but nothing is loaded.

I alays asumed that jScript ( jQuery ) is independent form host mechanisms. Am i wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="../../Scripts/jquery-1.5.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#MyButton').click(function () {
                //Load HTML from HelpDetails.html
                $('#OutputDiv').load('../HelpDetails.html #SubTOC');
            });
        });
    </script>
</head>
<body>
    <button id="MyButton">Click to Get HTML</button>
    <div id="OutputDiv"></div>
</body>
</html>
3
  • 1
    1. What do you see in the console? 2. was jQuery loaded correctly? Commented May 23, 2012 at 13:42
  • 1
    jQuery works on the DOM, so the server side technology used is moot. Do you see any errors in the console? Commented May 23, 2012 at 13:43
  • 1
    Is the AJAX request being made? What response does the server give? You need to do at least some debugging. Commented May 23, 2012 at 13:45

4 Answers 4

1

What is firebug console saying ? The only reason i could think is a wrong (remote) file path. Make sure you have a file called HelpDetails.html in the location where jQuery load method is looking for. A 404 error ?

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

I guess because it's more comment role than an answer.
Thx indeed the script was not found thanks for the hint with firebug.
BTW The load only works whenthe site is hosted (e.g. IIS) right ? When just double clicking the file localy the jquery load das not work, does it?
load will work as long as you have a valid file location as the parameter. No matter it is in IIS or your local machine.
1

Possible problems can be: jQuery is not loaded (but very unlikely if it works in some cases), html is not loaded. To exclude both: check the console in your browser. If you don't know why, please post which browser you are using. Also, it might be a better idea to link your jQuery to a library of another host (e.g. Google's)

Comments

0

You could try using Server.MapPath("~/your-path-to-jquery") to get the path to your script, might be that it just cant be found.

1 Comment

Sever.MapPath won't really help outside of ASP.NET.
0

Change the script line to this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

2 Comments

There's nothing wrong with his script tag. If the JavaScript resource isn't found, that's an error to be fixed. But we don't know that.
I disagree. If the file isn't there, it won't work. Using the CDN would probably eliminate that issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.