I have 2 (local) subdomains: kohana.local.com and wordpress.local.com. jQuery plugin (.js) is located on kohana.local.com domain and takes care of rating articles and retrieving rate count on both domains. Controller_Rating extends Controller. Method (action_getrating) has following code (kohana 3.2):
if($this->request->post() && $this->request->is_ajax()){
$this->auto_render = FALSE;
echo "{$_REQUEST['callback']}(".json_encode($data).")";
}
Ajax call:
$.ajax({
type: "POST",
url: "http://kohana.local.com/rating/getrating",
dataType: "jsonp",
data: { some_id: id },
success: function(json){
//do something
}
});
When ajax call gets issued from kohana.local.com, everything works great. If it’s issued from wordpress.local.com $this->request->is_ajax() is false, and method is not “post”, but “get” somehow. What is the reason for this, and how to make it work? Post is required and is_ajax is good for security and validation.
Thanks in advance.
EDIT:
post to jsonp is not possible, so i can’t use this approach. i’ll have to try to find the solution in the direction of json
You can simply use
jsondataType, so you don’t need to use callbacks. Just add headerAccess-Control-Allow-Originto server which requests are made (kohana.local.com).All domains are allowed:
Or specify allowed domain:
Spec: http://www.w3.org/TR/2008/WD-access-control-20080912/#access-control-allow-origin
Multiple domain solution: Access-Control-Allow-Origin Multiple Origin Domains?