How can i make an ajax request through a link, i mean when i click on link <a href=.... it sends an ajax request to a php file which shows in my case a table?

Member Avatar for LastMitch

Send Ajax request through link

Can you post the code of what you have so far?

I assume you are using JQuery so it should look like this the first few lines:

$('?').click(function(e){
loadURL($(this).attr('href'))
$.post(...);
}

I got no idea. The is reason why is that it really depends what code you have to see how to approached this.

So those are the only 3 lines that I could think of.

The bottom line is that you need to execute JavaScript or jQuery AJAX related code when the hyperlink is clicked.

Here is an example tutorial that may help, native JavaScript, no jQuery. AJAX and PHP

commented: Nice! +10
Member Avatar for LastMitch

@JorgeM

I hope you get don't upset. It seems like you are promoting your website. Everyime I read threads that you provide a link from your website. I mean it's good! You organized it plus show code and demo. I like it alot. I'm gonna bookmark this.

commented: thank you for the feedback. Always good to get perspectives. +12

Yes , actuallu a tutorial was what i was looking for. Thanks

@LastMitch- I do realize it seems like I am promoting my site.... In a way, i guess I am. However, I am not trying to stuff my links in every thread like a typical spammer. I have been only including links when there is some demo or code that I've already written that is relevant. In some cases, its challenging to provide all of the info in one post so its easier to refer to something online. I post other links as well.

In reality, my site is comprised of quite a bit of tutorials that I have used over the last decade in the classroom and in training sessions. Some stuff that I have learned in the last past year regarding topics that have come up in this forum too... I just recently put it all together and posted it online because I found it easier to reference it. Feel free to use and adapt to your needs.

I am glad that the OP found it helpful and was able to use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.