Jump to content

Same ajax working on some pages and not others


mikwit

Recommended Posts

Thanks for your help, I have this javascript/php solution using ajax that works on some pages and not on others.

The general Idea: There is a link within a <span> that when clicked, fades out and fades back in with an updated message.  This message changes based on an id tag found in the link.  On some pages the id tag works fine, on others it fails. No clue why.  Here is the java script that feeds the php

 

Update: I have found that this occurs only on page that are redirected using mod_rewrite, any ideas?

 

$(function(){
$("a.vote_up").click(function(){
//get the id
the_id = $(this).attr('id');
$("span#votes_count"+the_id).fadeOut("fast");
	$.ajax({
		type: "POST",
		data: "action=vote_up&id="+the_id,
		url: "votes.php",
		success: function(msg)
		{
			$("span#votes_count"+the_id).html(msg);
			//fadein the vote count
			$("span#votes_count"+the_id).fadeIn("fast");		
		}
	});
});	
});

 

The php votes.php which is called is

$number = $_POST['id'];
$action = $_POST['action'];

if($action=='vote_up') //voting up
{
$q = "UPDATE main SET likes = likes + 1 WHERE number = $number";
setCookieVote($number);
}
$r = mysql_query($q);
if($r){
$votes = getAllVotes($number);
echo $votes[0];
}
elseif(!$r) //voting failed
{
echo "Failed!";
}
?>

Sometimes the id gets passed through and number is the id in the link, other times the number is blank.

This works:

<span class="votes" id="votes_count112"><a href="javascript:;" class="vote_up" id="112">1</a> </span>

While on another page with the same libraries loaded

<span class="votes" id="votes_count113"><a href="javascript:;" class="vote_up" id="113">1</a> </span>

does not work and returns "Failed!".

 

 

I know it's a little messy, I'm not too great and the project is pretty loose.

Thanks a lot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.