Ive been trying to create a div on my index page that onclick calls a js function that would submit the data to a php page for calculations and mysql queries. but not only does my chrome developers tools show that no POST request is even happening, but the page just refreshes the minute i click the submit button. my event handler on the main php page is onclick, which should lead to this function
function submitvote(uv){
$('#rank_IFC').html('<img src="ajax-loader.gif">').show();
var sortdata = $('ul.sort').sortable('toArray').join(',');
var url= "results.php";
$.post(url, {Tablename:uv, sortdata: sortdata}, function(){
$('#rank_IFC').html('').show();
});
}
which should than lead to my php conditional,
<?php if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');
// Including file for the DB connection:
require 'connect.php';
// If the poll has been submitted:
$tablename=$_POST['Tablename'];
if($tablename=='IFC')
{
$userOrder=$_POST['sortdata'];
// The data arrives as a comma-separated string,
// so we extract each post ids:
$data=explode(',',str_replace('li','',$_POST['sortdata']));
// Getting the number of objects
list($tot_objects) = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sort_objects"));
if(count($data)!=$tot_objects) die("Wrong data!");
foreach($data as $k=>$v)
{
// Building the sql query:
$str[]='('.(int)$v.','.($tot_objects-$k).')';
}
$str = 'VALUES'.join(',',$str);
// This will limit voting to once a day per IP:
mysql_query(" INSERT INTO `sort_votes` (ip,date_submit,dt_submit,userOrder,Tablename)
VALUES ('".$_SERVER['REMOTE_ADDR']."',NOW(),NOW(),$userOrder,$tablename)");
// If the user has not voted before today:
if(mysql_affected_rows($link)==1)
{
mysql_query(' INSERT INTO `IFC` (id,votes) '.$str.'
ON DUPLICATE KEY UPDATE votes = votes+VALUES(votes)');
}
}
my main index page is in php. my question is, why is no AJAX post request being made when the function is called?