lundi 3 juin 2019

Ajax.load wont work when pressing a button [duplicate]

I am trying to run ajax.load method when pressing a button. The idea is very simple: change the body of a to something else, by using the ajax.load method. However, i havent been succesful yet, and after researching for a couple of hours, i still havent found the solution. Nothing happens when i press the button.

i have tried to copy/paste one of w3schools examples into my own project, just to see if it works on my computer. The result was that it didn't work on my computer, even after changing the files in the example to my own files. this makes me think that there is a problem with how ajax has been put into the project. but i am not sure. The example is here: https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_load

my test-website is running on a tomcat server and is written in intelliJ. Here is the code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AjaxTest</title>
</head>
<body>
<script>
    $("#button").click(function () {
        $("#maincontainer").load("ajaxTestAlternativeText.txt")
    })

</script>

<div id="maincontainer">
    this text needs to change
</div>

<button id="button" type="button"> tryk her :)</button>


</body>
</html>

in the code above, i change the body to a .txt file. I have also tried with changing to a .html file, but that didn't work either.




Aucun commentaire:

Enregistrer un commentaire