Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Javascript to work? $.ajax not working right?
    primarykey
    data
    text
    <p>So, the Javascript code which can be found below doesn't seem to be functioning properly.</p> <p>The goal is to get the text below the map to change on hover of the rooms.</p> <p><a href="http://zadias.me/SVG/PresParkEisenhower.html" rel="nofollow">Map Page</a></p> <p>The JSON (zadias.me/SVG/rooms.json) data that pulls the data seems to be where I'm faulting, I think. When I test/debug the code by placing .innerHTML statements that would print in the text field, it would work if I placed the .innerHTML before the $.ajax, however, if I put the .innerHTML function in the "success" part of the .ajax, it wouldn't work..</p> <p>Javascript:</p> <pre><code>$(document).ready(function(){ var json = (function () { //this function obtains the data var json = null; $.ajax({ 'async': false, 'global': false, 'url': 'http://zadias.me/SVG/rooms.json', 'dataType': "json", 'success': function (data) { json = data; } }); return json; })(); function hashTag(){ var hashTag, hash2; hashTag = location.hash; //obtains the part of the URL with the hash tag and what follows hashTag = hashTag.replace(/#*/, ''); //replaces the hash tag if(hashTag.length &gt; 0){ for(i=0 ; i&lt;json.rooms.length ; i++){ if (json.rooms[i].roomId == hashTag) //linear search through array of rooms to see if any equal the hashTag { document.getElementById('room_info').innerHTML = '&lt;img src="images/' + json.rooms[i].image + '" /&gt;&lt;h4&gt;' + json.rooms[i].name + '&lt;/h4&gt;' + json.rooms[i].HTMLdescrip; } //loads the data from the JSON data. } } }; function setHash(){ window.location.hash = this.id; //creates the hash link based on the object's id (object id acquired from the JSON data) and sets it }; function setHTML(){ for(i=0 ; i&lt;json.rooms.length ; i++){ if (json.rooms[i].roomId == this.id) { document.getElementById('room_info').innerHTML = '&lt;img src="images/' + json.rooms[i].image + '" /&gt;&lt;h4&gt;' + json.rooms[i].name + '&lt;/h4&gt;' + json.rooms[i].HTMLdescrip; } } }; window.onload = hashTag(); $(".active").click(setHash); $(".active").mouseenter(setHTML); //$(".active").mouseover(setHTML); $(".active").mouseleave(hashTag); }); </code></pre> <p>I understand that it's a bit localized, how could I change this up?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload