Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  115] [ 6]  / answers: 1 / hits: 27775  / 13 Years ago, mon, february 13, 2012, 12:00:00

I cannot get this to work, the page already has other jquery functions running completely fine so i know jquery is working (jplayer and lazyload work fine)



here is my javascript function:



<script type=text/javascript>
function upone() {
$.get(upone.php);
return false;
}
</script>


Here is my link



<a href=# onclick=upone();>Like</a>


and my php file upone.php is :



<?php
include(include/config.php);
include(include/functions/import.php);

if(isset($_SESSION['USERID'])&&$_SESSION['USERID']>=0&&is_numeric($_SESSION['USERID']))
{
$USERID=$_SESSION['USERID'];

$query=INSERT INTO audio_like SET USERID='.mysql_real_escape_string($USERID).';
$result=$conn->execute($query);
}

?>


the php file runs fine if i manually link to it, clicking on the link also results in the page refreshing with the # added to the page. Any ideas?


More From » php

 Answers
1

Rather than using inline javascript, try doing something like this.



Give the Like link a class, example:



<a href='#' class='likeLink'>Like</a>


An instead of your current section, use something like this:



<script>
$(function() {
$('.likeLink').click(function() {
$.get('upone.php', function(data) {
alert(Server Returned: + data);
});
return false;
});
});
</script>


If the alert message returns what you expect from the PHP page, you can just comment it out for production.



By the way, I typed this out a long time ago today and forgot I was working on it. Sorry if it's already solved.


[#87498] Sunday, February 12, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarod

Total Points: 62
Total Questions: 111
Total Answers: 83

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
jarod questions
;