I am currently developing a project using jquery ajax functions. I just want the ajax function to display some text from a file on the server when a button is clicked, but when I click the button it does nothing. I tried adding an error message but that doesn't seem to work either. I've made sure to use a version of jquery that supports ajax functionality, I've even copied and pasted code from a source that I know works, but nothing seems to work.
My java script file
window.onload=loadDoc(); $(document).ready(function(){ // the function that should be getting called $("#accountInfo").click(function(){ $.ajax({url: "accountPerks.txt", error: function(xhr, status, error) { var err = eval("(" + xhr.responseText + ")"); alert(err.Message); }, success: function(result){ $("#perksDiv").text(result); }}); }); }); //everything below here are functions for separate pages $(document).ready(function(){ $("#member1Info").click(function(){ $("#BandMember1").css("visibility", "visible"); }); }); $(document).ready(function(){ $("#member2Info").click(function(){ $("#BandMember2").css("visibility", "visible"); }); }); $(document).ready(function(){ $("#member3Info").click(function(){ $("#BandMember3").css("visibility", "visible"); }); }); function newAlbum(){ var node = document.createElement("li"); var textNode = document.createTextNode("aaaaallllpxas(2023)"); node.appendChild(textNode); document.getElementById("albumList").appendChild(node); $("#sneakPeak").css("visibility", "hidden"); } var getAlbum = document.getElementById("sneakPeak"); getAlbum.onclick=function(){ newAlbum(); } function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function(){ if(xhttp.readyState == 4 && xhttp.status == 200){ document.getElementById("ExtraText").innerHTML = xhttp.responseText; } }; xhttp.open("GET", "TourInfo.txt", true); xhttp.send(); }
The page I want the text file to appear on
CMP204 Unit Two Coursework Template User Profile
"; ?> // this button should display the text from the server
// the text from the server should be showing in this paragraph
Here are all the gigs you have attended
Use only 1 document function, if you use too many $(document) functions, only the last function will be returned in the response.
And use the other functions you want to run that will be loaded in the window.load function