不,您没有通过jQuery AJAX调用传递cookie。。当然不是通过跨域访问。
如果要使用jQuery传递数据,则需要传递当前用户ID并使用get_userdata($userid)
确定用户是否具有正确的功能。
服务器端:
$jQuery_user = get_userdata($_POST[\'user_id\']);
if(!user_can($jQuery_user,\'publish_posts\')){
return array(\'reply\'=>0,\'error\'=>\'Forbidden\',\'code\'=>\'403\');
}
客户端:
// Be sure your form can somehow provide the currently logged in user id, hidden or otherwise.
var idata = {};
idata[\'url\'] = form.find(\'#attachment\').val();
idata[\'nOnce\'] = form.find(\'#nOnce\').val();
// if you have a nonce, you should be able to get user_id
iData[\'user_id\'] = jQuery(\'#user_id\').val();
// snip (etc.)
jQuery.ajax({
type: "POST",
url: vars.path+\'/post\',
data: JSON.stringify(idata),
contentType: "application/json; charset=utf-8",
crossDomain: true,
dataType: "json",
success: function (data, status, jqXHR) {
// snip
},
error: function (jqXHR, status) {
// snip
}
});