I’m sendint serialized data to items.php file with AJAX, I’m checking result with FireBug, AJAX send data like this category=2 my items.php file is:
<?php
require_once('db.php');
if (isset ($_POST['category'])) {
$kat = mysql_real_escape_string($_POST['category']);
if ($kat == 0){
$kat = '';
}elseif ($kat == 1){
$kat = 'ORDER BY date DESC';
}elseif ($kat == 2) {
$kat = 'ORDER BY price DESC';
}elseif ($kat == 3) {
$kat = 'ORDER BY price';
}
}else{ $kat = '';}
$query = "SELECT * FROM prekes ".$kat."";
mysql_query("SET NAMES 'UTF8'");
$q = mysql_query($query) or die(mysql_error());
$i = 0;
while($f = mysql_fetch_array($q)){
echo '<div kaina="'.$f['kaina'].'" class="prekes"><img src="prekes/'.$f['foto'].'">'.$f['pavadinimas'].'<br /><strong>'.$f['kaina'].'Lt </strong></div>';
}
?>
and here is my AJAX success function:
$.ajax({
type: 'POST',
url: 'items.php',
data: cleaned,
success: function () {
$('#items').fadeOut("fast").load("items.php?ts="+ $.now()).fadeIn("fast");
}
});
Div refreshes after success, but I’m getting old, unordered result. Why does it happening?
Since
loadmethod uses jQuerygetmethod internally, I guess you are getting cached data. Make sure to send a unique key as part of the querystring and it will give you the new content /result /uncached data. You may use theDateobject to get create a new unique string;EDIT : jQuery has a small method called
$.now()to give you a unique timestamp. you may use that instead of writing the Date().getTime() method.Thanks Kevin for pointing out. 🙂
EDIT 2 : After seeing the code
1) You are not passing the
categoryquerystring value which is being used to return the ordered list.You should pass that like this2)
loadmethod is aGETrequest. in your PHP code(items.php) you are accessing it using $_POST(is that correct ? Shouldnt be $_GET ?So Change
to