我的页面模板文件(如下)中有以下代码,当与正常表单提交一起使用时,这些代码可以正常工作。
我试图做的是在更改select下拉列表时使用ajax(无页面刷新)更新get\\u pages变量。我可以看到firebug控制台中返回的数据,但似乎无法将其返回到php代码/变量。
任何帮助都将不胜感激,s。
<?php
if ( isset($_POST[\'sortables\']) ) :
$sortables = $_POST[\'sortables\'];
else :
$sortables = \'menu_order\';
endif;
if ( isset($_POST[\'ascdesc\']) ) :
$ascdesc = $_POST[\'ascdesc\'];
else :
$ascdesc = \'asc\';
endif;
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#sort, #ascdesc").change(function() {
var $form = $("#myForm");
var dataString = $form.serialize();
$.ajax({
type: "POST",
url: "<?php the_permalink(); ?>",
data: dataString,
success: function() {
console.log(dataString);
}
});
});
});
</script>
<?php $thispage=$post->ID; ?>
<section id="list-boxes">
<form action="<?php the_permalink(); ?>" method="post" id="myForm" style="margin:5px 0 15px;">
<select name="sortables" id="sortables">
<option value="menu_order"<?php if ($_POST[\'sortables\'] == \'menu_order\') echo \'selected="selected"\'; ?>>Sort by Menu Order</option>
<option value="post_title"<?php if ($_POST[\'sortables\'] == \'post_title\') echo \'selected="selected"\'; ?>>Sort by Title (Alphabetically)</option>
<option value="post_date"<?php if ($_POST[\'sortables\'] == \'post_date\') echo \'selected="selected"\'; ?>>Sort by Date Created</option>
<option value="post_modified"<?php if ($_POST[\'sortables\'] == \'post_modified\') echo \'selected="selected"\'; ?>>Sort by Date Modified</option>
</select>
<select name="ascdesc" id="ascdesc">
<option value="asc"<?php if ($_POST[\'ascdesc\'] == \'asc\') echo \'selected="selected"\'; ?>>Ascending</option>
<option value="desc"<?php if ($_POST[\'ascdesc\'] == \'desc\') echo \'selected="selected"\'; ?>>Descending</option>
</select>
<button type="submit" id="sort-submit">Sort</button>
</form>
<?php $pages = get_pages(\'child_of=\'.$thispage.\'&sort_column=\'.$sortables.\'&sort_order=\'.$ascdesc.\'&parent=\'.$thispage.\'&number=2\'); $count = 0; foreach($pages as $page) : $content = $page->post_excerpt; $link = get_page_link($page->ID); ?>