...

View Full Version : AJAX help, PHP submit without refresh



jquadr01
03-10-2011, 07:11 PM
I have a different ajax function for each submit button but it does not work. It is on an auto-refresh of the div "content". Can anyone point out my mistakes?


<script type='text/javascript'>
int likes, count, dlikes, nova;
function doWorkl(){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open('POST', 'post.php?likes='
+(likes+1),
+'count='+count,
+'dlikes='+dlikes,
+'nova='+nova,true);
httpObject.send(null);
}return:false;
}

function doWorkdl(){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open('POST', 'post.php?likes='
+likes,
+'count='+count,
+'dlikes='+(dlikes+1),
+'nova='+nova,true);
httpObject.send(null);
}return:false;
}
function doWorkn(){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open('POST', 'post.php?likes='
+likes,
+'count='+count,
+'dlikes='+dlikes,
+'nova='+(nova+1),true);
httpObject.send(null);
}return:false;
}
function doWorkr(){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open('POST', 'post.php?likes='
+likes,
+'count='+count,
+'dlikes='+dlikes,
+'nova='+nova,true);
httpObject.send(null);
}return:false;
}

</script>




<link rel='stylesheet' type='text/css' href='style.css'>

<script language='javascript' type='text/javascript'>
setInterval(function() {
$('#content').load(location.href+' #content>*','');
}, 5000);
</script>
</head><body>


<div id=top>

<center>
<table><tr><td>";


mysql_select_db("$db_database", $con);




$result = mysql_query("$norm");
$count=0;


while($row = mysql_fetch_array($result))

{

echo "<script type='text/javascript'>";
echo "likes=";
echo $row['likes'];
echo ";, count=";
echo $row['count'];
echo ";, dlikes=";
echo $row['dlikes'];
echo ";, nova=";
echo $row['nova'];
echo ";";


echo "</script>";


if(isset($_COOKIE['likesbn'.$row[count]]) || isset($_COOKIE['dlikesbn'.$row[count]])){
$likesbn= "<span id=sub style='color:#6D6968!important;'>[Agree]</span><div style='display:none;'>";
$likesbndiv="</div>";
$dlikesbn= "<span id=sub style='color:#6D6968!important;'>[Disagree]</span><div style='display:none;'>";
$dlikesbndiv="</div>";
}
else{
$likesbn= "";
$likesbndiv="";
$dlikesbn= "";
$dlikesbndiv="";}



if(isset($_COOKIE['novabn'.$row[count]])){
$novabn= "<span id=sub style='color:#6D6968!important;'>[Villanova's Voice]</span><div style='display:none;'>";
$novabndiv="</div>";
}
else{$novabn= "";
$novabndiv="";}

if(isset($_COOKIE['reportbn'.$row[count]])){
$reportbn= "<span id=sub style='color:#6D6968!important;'>[Report]</span><div style='display:none;'>";
$reportbndiv="</div>";
}
else{$reportbn= "";$reportbndiv="";}



echo "<div id=content>";
if($count<=$hn){ if($count<$ln || $count>$hn){echo "<div style='display:none;'>";}

echo "<center>";
echo "<table id='table'>";

echo "<tr><td valign='center' colspan='5'><br>";

echo "<p align=left style='font-size:12;'>";
echo $row['post'];
echo "</p>";

echo "<br /></td></tr><tr><span style='font-size:12;'>";

echo "<td valign='bottom'>";
echo "<form name='myform1'>";
echo $likesbn;
echo "<input id=sub style='cursor: pointer;' type='submit' onclick='doWorkl();' value='[Agree]'>";
echo $likesbndiv;
echo $dlikesbn;
echo "<input id=sub style='cursor: pointer;' type='submit' onclick='doWorkdl();' value='[Disagree]'>";
echo $dlikesbndiv;
echo $novabn;
echo "<input id=sub style='cursor: pointer;' type='submit' onclick='doWorkn();' value='[Villanova&#039;s&nbsp;Voice]'>";
echo $novabndiv;
echo $reportbn;
echo "<input id=sub style='color:red!important;cursor: pointer;' type='submit' onclick='doWorkr();' value='[Report]'>";
echo $reportbndiv;
echo "</form>";
echo "</td>";

echo "</table>";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum