Basically I have a href that passes through the id of an image via json which looks like this:
http://localhost:4567/public/vote.html?image=50b4d006fa4634bb130000fe
this then creates/updates an image in mongo based on the id and updates if the user/visitor has voted.
at the moment i use silex to redirect after the code within that vote.html has been processed:
return $app->redirect('popular.html');
i was wondering if it was possible to use jquery to process the above href without redirecting, so basically i could click vote and the number would change seamlessly without the user knowing they have been redirected.
answered
sorry for the vague question but my answer does come from the principle of that posted below.
i changed the href to assign a class of vote & the id of the image:
<a class="vote" id="' + image.id + '" href="#">
then added this to my $(document).ready function:
$(".vote").live('click', function() {
$('span', this).toggle();
$.ajax( site_url + 'vote.html?image=' + $(this).attr('id'));
});
this in theory uses the id of the mongo object and appends it to the url for each time the object is clicked, processing the href without redirecting.
Yes, you can use a bit of jQuery to help you out. This is a very contrived example, as you have not provided any HTML markup examples for your vote buttons / images.