mikwit Posted December 27, 2010 Share Posted December 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222753-same-ajax-working-on-some-pages-and-not-others/ Share on other sites More sharing options...
mikwit Posted December 28, 2010 Author Share Posted December 28, 2010 Solved the problem, had to do with 404 redirecting and / missing from vote.php in the url part of the ajax code Quote Link to comment https://forums.phpfreaks.com/topic/222753-same-ajax-working-on-some-pages-and-not-others/#findComment-1152250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.