I'm trying to learn some basic AJAX. But I'm darned if I can get nonces to work correctly.
Below is a cut-down, simplified version of what I'm trying to do. Basically, it allows users to sort some boxes on screen. And as they're sorted, that data is sent to process-sortable.php. Then it spits out a message in a box on the page. Nothing exciting and it does work ... except for when I try to use nonce protection on it. Then it just spits out -1 to indicate that the nonce was rejected.
Any ideas what I'm doing wrong?
index.php
PHP Code:<?php
require( '../../../wp-load.php' );
define( 'TEST_URL', get_bloginfo( 'wpurl' ) . '/wp-content/plugins/ajax_test/' );
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PixoPoint AJAX text</title>
<script type='text/javascript' src='<?php echo get_bloginfo( 'wpurl' ); ?>/wp-admin/load-scripts.php?c=1&load=jquery,utils&ver=d24248fe4b0cd62086633fd42ef1019b'></script>
<style type="text/css">
#widgetbox div .handle {display:block;background:#ddd;padding:10px;width:150px;border:1px solid #aaa;margin:10px;}
#widgetbox div#info {background:#ffcccc;color:#222;position:absolute;left:200px;top:0;padding:10px;font-family:verdana,sans-serif;font-size:30px;font-weight:bold;}
</style>
</head>
<body>
<div id="widgetbox">
<div id="listItem_1">
<span class="handle">111111111</span>
</div>
<div id="listItem_2">
<span class="handle">222222222</span>
</div>
<div id="listItem_3">
<span class="handle">333333333</span>
</div>
<div id="info"></div>
<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery("#order").sortable({
placeholder: "ui-selected",
revert: false,
tolerance: "pointer"
});
jQuery("#widgetbox").sortable({
handle : '.handle',
update : function () {
var order = jQuery('#widgetbox').sortable('serialize');
jQuery("#info").load("<?php
echo wp_nonce_url( TEST_URL . 'process-sortable.php?action=getorder', 'pixopoint_getorder' );
?>?"+order);
}
});
});
</script>
<script type='text/javascript' src='<?php echo get_bloginfo( 'wpurl' ); ?>/wp-admin/load-scripts.php?c=1&load=hoverIntent,common,jquery-color,jquery-ui-core,jquery-ui-sortable,jquery-ui-tabs&ver=61f28a5f9179fe02e40cff05d5fad5b6'></script>
</body>
</html>
process-sortable.php
PHP Code:<?php
define( 'DOING_AJAX', true );
require( '../../../wp-load.php' );
check_ajax_referer( 'pixopoint_getorder' );
echo '
Yay! It worked :D
';
?>


LinkBack URL
About LinkBacks
Reply With Quote
