我遇到的问题是我的 jquery 脚本没有将成功返回给 div,而是简单地重新加载页面(这应该是不可能的)。我的代码如下。任何帮助都会很棒,因为我花了很多时间试图让它发挥作用。
$(document).ready(function() {
var loader = "<img src='images/ajax-loader.gif' alt='loading...' />";
$('#paging_container').pajinate({
show_first_last: false,
nav_label_next : '>',
nav_label_prev : '<'
});
var loadUrl2 = "productadminprocess.php";
$(".action_buttons").click(function() {
$("#rightcolumn").html(loader).load(loadUrl2, {productid: $(this).attr("id")});
});
$("#thesubbie").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var loadUrl3 = "sortitems.php";
var $form = $( this ),
input = $form.find( 'input[name="sort_item"]' ).val();
var myRadio = $('input[name=sorters]');
var checkedValue = myRadio.filter(':checked').val();
$.post(loadUrl3, {radio: checkedValue, sort_item: input},
function(data){
var content = $(data);
$('#thebox').html(content);
});
});
});
这是返回数据的 PHP 脚本(本质上是一种排序)
function secure($x) {
$x = mysql_real_escape_string($x);
$x = stripslashes($x);
return $x;
}
$sorters = secure($_GET['sorters']);
$sort_item = secure($_GET['sort_item']);
//Start main query
$products = "SELECT * FROM product_list WHERE name_family = '$sort_item'";
//echo $products;
$list = mysql_query($products);
//echo $list;
while($row = mysql_fetch_array($list)) {
$id = $row['id'];
$name = $row['product_name'];
?>
<div class="products"><img src="images/Product_thumbail.png" width="200" height="220" title="<?php echo $name; ?>" alt="<?php echo $name; ?>"><div class="action_buttons" id="<?php echo $id; ?>">Update</div></div>
<?php
} // end while
?>