-1

Hey guys what am I doing wrong here? Im trying to make it so that when I click the different ids, it will load the external txt and html into the div with the id of "jersey". RIght now when i click nothing happens it just stays the same.

<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">    </script>
<script type="text/javascript">


$(document).ready(function() {
$("#test").click(function() {
    $("#jersey").load("ajaxtest.txt");
});


$("#testtwo").click(function() {
    $("#jersey").load("ajaxtesttwo.html");
});
});

</script>


</head>

<body>

<a href="#" id="test">Test 1</a>||<a href="#" id="testtwo">Test 2</a>
<div id="jersey">what a wonderful world</div>
<br clear="all" />


</body>
</html>
  • @Elvanos — No. `load` does that for you – Quentin Mar 26 '16 at 20:59
  • There's nothing obviously wrong with the code. I can think of a possible reason why it might not work, but that would be obvious if you opened the Developer Tools in your browser and looked at the Console. Have you done that very basic bit of debugging? – Quentin Mar 26 '16 at 21:00
  • here is link for your answer check this out [http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local](http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local) – Asad Mar 26 '16 at 21:12

1 Answers1

-1

Pretty sure you need to load the external file content into a variable and then use some kind of append function, like this:

$(document).ready(function() {
$("#test").click(function() {
    var temp_content = $.load("ajaxtest.txt");
    $("#jersey").html(temp_content);
});


$("#testtwo").click(function() {
    var temp_content = $.load("ajaxtesttwo.html");
    $("#jersey").html(temp_content);
});
});
Elvanos
  • 302
  • 2
  • 4
  • No. The whole point of the `load` method is that it does that for you. It certainly doesn't perform a synchronous HTTP request and return the result as a string. – Quentin Mar 26 '16 at 21:01
  • I don't understand any of this stuff really I've been doing it all from reading and/or YouTube. Where in that link is it telling me what to do? All the files are in the same folder. I don't know why they would t connect. – JCAthletics Mar 26 '16 at 22:19