I’m new to Jquery and trying to make a http request so that I don’t have to leave the current page, but
var getURL = $("#callerId").attr("href");
does not seem to be working
console.log(getURL) displays “undefined”
there’s the source code (everything down to callerId should be correct)
<script type = "text/javascript">
$(document).ready(function() {
$('ul.hrefURL a').click(function(dontRedirect) {
dontRedirect.preventDefault();
var callerId = event.target.id;
var getURL = $("#callerId").attr("href");
$.ajax({
type : "GET",
url: getURL,
success: function(response){
alert($('#response'));
}
});
});
});
</script>
<a href="javascript:document.location = TTS1" id = "1T">
You need to use
instead of
In the first case
$(this)points to the jquery object of the anchor you just clicked, in the second – it points to some element that isn’t even covered by your exampleLive example: http://jsfiddle.net/zerkms/YJRLR/