Trying to load a page into a div with AJAX

This is a map of the united states. I am using area coordinates to make hotspots on the map. When a user clicks the hotspot  I want to load info about that State into the div "myArea" using ajax. I have tried and tried, the Jquery is not binding to the link. Every time i click the area link it goes to the page instead of loading the page in the div with ajax.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>MAP</title>
<link href="style.css" rel="stylesheet" type="text/css">

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




<script>
$(function() {
		$('.map').maphilight();
	});
		
</script>	


</head>

<body>


<img class='map' src="SitePad_Test.jpg" alt="" width="3840" height="2160" usemap="#Map"/>
<map name="Map">
  <area class="link" shape="poly" coords="1017,389,840,225,840,170,838,100,1071,101,1071,332" href="gpio.php?psh1" alt="build_1"  onclick="play()">
  <area class="link" shape="poly" coords="1057,427,1244,227,1247,104,1414,107,1411,204,1460,254,1184,558" href="gpio.php?psh2" alt="blding_2"  onclick="play()">
  <area class="link" shape="poly" coords="1076,596,927,733,824,638,835,354,1037,545" href="gpio.php?psh3" alt="building_3"  onclick="play()">
  <area class="link" shape="poly" coords="1677,379,1544,253,1546,86,1712,91,1713,176,1793,258" href="gpio.php?psh4" alt="building_4"  onclick="play()">
</map>
	
<audio id="audio" src="audio/digi_plink.wav" ></audio>

<script>
/*
  function play(){
   var audio = document.getElementById("audio");
   audio.play();
			 }
*/
</script>
	
	
<div id='myArea'>here</div>



<script type="text/javascript">
$(document).load(function(){
 $("area.link").click(function(){
	 event.preventDefault();
        $("#myArea").load($(this).attr("href")); 
        return false;
    })
});
</script>

	
	
</body>
</html>

Open in new window

Zeke RichOwnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
based on your current code, you got a Reference Error: play is not defined.

reason being your function is remarked:

<script>
/*
  function play(){
   var audio = document.getElementById("audio");
   audio.play();
                   }
*/

</script>

also change:
onclick="play()"

Open in new window

to:
onclick="return play()"

Open in new window


make your play function to return false:

function play(){
   var audio = document.getElementById("audio");
   audio.play();
   return false;
                   }

full codes:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>MAP</title>
<link href="style.css" rel="stylesheet" type="text/css">

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




<script>
$(function() {
		$('.map').maphilight();
	});
		
</script>	


</head>

<body>


<img class='map' src="SitePad_Test.jpg" alt="" width="3840" height="2160" usemap="#Map"/>
<map name="Map">
  <area class="link" shape="poly" coords="1017,389,840,225,840,170,838,100,1071,101,1071,332" href="gpio.php?psh1" alt="build_1"  onclick="return play()">
  <area class="link" shape="poly" coords="1057,427,1244,227,1247,104,1414,107,1411,204,1460,254,1184,558" href="gpio.php?psh2" alt="blding_2"  onclick="return play()">
  <area class="link" shape="poly" coords="1076,596,927,733,824,638,835,354,1037,545" href="gpio.php?psh3" alt="building_3"  onclick="return play()">
  <area class="link" shape="poly" coords="1677,379,1544,253,1546,86,1712,91,1713,176,1793,258" href="gpio.php?psh4" alt="building_4"  onclick="return play()">
</map>

<audio id="audio" src="audio/digi_plink.wav" ></audio>

<script>

  function play(){
   var audio = document.getElementById("audio");
   audio.play();
   return false;
			 }

</script>
	
	
<div id='myArea'>here</div>



<script type="text/javascript">
$(document).load(function(){
 $("area.link").click(function(){
	 event.preventDefault();
        $("#myArea").load($(this).attr("href")); /*$("#myModal").load($(this).attr("href"));*/
        return false;
    })
});
</script>

	
	
</body>
</html>

Open in new window

Leonidas DosasCommented:
I tested your code and you don't have any syntactical or  logicall errors.I think that your problem is the path directory in the href attr. Check to be the right.
Chris StanyonWebDevCommented:
Couple of things wrong with your jQuery.

The event you want to be binding to is ready, not load. You also need to pass the event arg into the click event handler for it work properly:

$(document).ready(function(){
  $("area.link").click(function(event){
    event.preventDefault();
    $("#myArea").load($(this).attr("href")); /*$("#myModal").load($(this).attr("href"));*/
  });
});

Open in new window

You should also consider updating your jQuery library. The one you're using is way out of date.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Zeke RichOwnerAuthor Commented:
Ryan Chong I did remove all instances related to playing audio and the script still did not work. But i will re-implement the audio using part of the code you supplied so i thank you for that. Chris Stanyon your code did correct the problem and was the correct answer. Thank you much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.