![]() |
Using ajax to transform links after they have been clicked to update a database
On a page I have links (produced by a PHP loop) which look like this:
Code:
<div class="tools">When a user clicks one of these links, the receiving processor.php script takes the key-value pairs from the query string, and uses them to update a database and then build a new form of the link. (The new form of the link is such that a "like this" link turns into an "unlike this" link, and vice-versa.) It does all this successfully. What I want to do is use ajax (as I understand, best using jquery) to insert this newly built link in place of the one that was clicked, without having to refresh the page. As I understand it, to make this happen, I need to include jquery, and also place a js function in the head section of the page. I tried this js function suggested on another forum for the purpose: Code:
<script type="text/javascript">What function would work for me? |
Yes I did realise that jquery isn't necessary, but I got the impression it helped in the sort of problem I was looking to solve, but thanks for the reminder.
I found that the function works if I wrap the code in a document.ready callback to ensure that it executes after the DOM has loaded: Code:
<script type="text/javascript">Code:
<style type="text/css">(I removed the fadeout effect, which broke my layout, but obviously that has nothing to do with the css "link transformation" not working after the click.) |
I removed the class from the links that turned them via css into rollover images. Now they're just text links, like this:
Code:
<div class="tools">Now my problem is that, although the ajax function successfully replaces the link address, it doesn't replace the link's class, or its title. The receiving processor.php script takes the variables from the link's query string in the links as above, and returns a new replacement link address in this form (example of a "like" link being replaced with an "unlike link"): Code:
processor.php?c=cars&p=2&s=d&u=d&link=5&pid=999999990But how can I modify the javascript function and/or the returned replacement link so that the link's class and its title is replaced, as well as the address? |
| All times are GMT +1. The time now is 09:44 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.