我想向跨站点请求“ domain1”上的wordpress安装。该请求来自“ domain2”上的项目,在该项目中我无法使用jQuery。 wordpress安装只是坚定不移的“ 400 Bad Request”。我在做什么错了?
// wordpress theme part on domain1:
class mytheme {
public function _init() {
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
add_action('wp_ajax_myajax', array($this, 'myajax'));
}
public function myajax() {
echo json_encode(array("test"));
exit();
}
}
// js code on domain2:
new Ajax.Request("https://domain1/wp-admin/admin-ajax.php?action=myajax", {
method: 'get',
onComplete: function() {
}
});