0

I can not seem to get the jQuery load function to work.

My HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<script  type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="Jquery_script.js"></script>

<script>$(document).ready(function(){ladda(); });</script>
</head>

<body>

<form namne="load">
<fieldset>
    <legend>load</legend>
        <table>
        <tr>
            <td><div id="L1"><h1>vill du ändra denna text</h1></div></td>
        </tr>
         </table>
    <button id="load_text">ändra</button>
</fieldset>
</form>


</body>
</html>

the problem is that the load button does not load external content

the javascript file:

(function($){
    ladda = function() {
    $("#load_text").click(function(){
            $("#L1").load("innehall.txt", function() {
                alert('Load was performed.');
            });
        });
    };
})(jQuery);

and the external .txt file only

<h2>du har ändrat innehållet</h2>
<p>detta är det nya innehållet</p>

Please help my figure out why the .txt file not is replacing the div id="L1" tag when pressing the button "ändra".

Dan Crews
  • 3,067
  • 17
  • 20

1 Answers1

0

Check path to your file and note: Chrome (if you use that browser) not allows local XHR requests (you can't use less.js with local .less files, for example).

Jessey
  • 46
  • 3
  • If you write .load('filename.txt') file must be located in same directory as your html file. Also, which browser you using? – Jessey Dec 19 '12 at 21:33
  • it's in the same directory and i have tried it in safari and chrome – Josef Carlsson Dec 19 '12 at 23:26
  • Try to open developer toolbar in Chrome (press F12), go to Console tab and refresh your page. Post here errors, if it has. – Jessey Dec 19 '12 at 23:30
  • Also, read that http://stackoverflow.com/questions/2990518/jquery-load-not-working-in-chrome page for more explanation. – Jessey Dec 19 '12 at 23:54