Your approach looks great to me, but jQuery does not have the $ _SERVER variable, as PHP does. The URL you would like to provide would be window.location (I believe that an empty string will work as well, or you can just provide the URL yourself). It seems you are just sending an identifier, so this will work.
If you want the page to respond to this change, you can add a callback function to $.post() . You can do different things.
$.post(window.location, {id: this.id}, function (data) { //one location.reload(); //two $("#responsedata").html(data); //three $("#responsedata").load("affected_page.php #output"); });
I think number 2 is the most elegant. It does not require a page reload. Ask the server-side php script to cancel all the data you want to return (json, html, whatever) and it will be placed in the data above for jQuery to process as you like.
By the way, on the server side performing the request, do not forget to sanitize $ id and put it in quotation marks. You do not want someone SQL injecting you.
source share