I have 6 different links,and each link is going to call a different Ajax function.
I'm using the <a href>
tag because I want it to appear as a link....Can I use this tag to call the Ajax function? or it only works with URL links?
THANKS!
I have 6 different links,and each link is going to call a different Ajax function.
I'm using the <a href>
tag because I want it to appear as a link....Can I use this tag to call the Ajax function? or it only works with URL links?
THANKS!
This is how I call mine. I give my elements a class name such as 'clickable' then use Jquery's click function as so.
$('.clickable').click(function() {
//do ajax
});
Then in the function, I get the id of the element as so. var id = this.id
, this will get the unique id of the element.
After that I use the $.post
method of Jquery, the shorthand version of ajax and complete whatever call you need to make when the user clicks that link using the id.
Of course, in my case I never use the anchor tag, I just make is a button or apply the . click
to the element I wish to add the ajax call to, but you could just surround the "link" in a span or a div to simulate the same effect.
Hope this helps in some way or another.
<a href="#" onclick="function()">Text</a>
or even as they wrote, with jquery
<a href="#" id="blabla">Text</a>
<script type="text/javascript">
$(document).load(function(){
$('#blabla').click(function(){
alert("Clicked");
});
});
</script>
Yes you can incorpore the link in the following way:
- on your link you can write <a href="#" onclick="function()">...</a>
Here you can see further information about this topic:
What is the difference between the different methods of putting JavaScript code in an ?
You can extract the value of the href
attribute and use it for your AJAX call...
(it is actually the proposed way to handle it..)