1

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

markoc
  • 83
  • 1
  • 7

1 Answers1

0

You can simply use json dataType, so you don't need to use callbacks. Just add header Access-Control-Allow-Origin to server which requests are made (kohana.local.com).

All domains are allowed:

Access-Control-Allow-Origin: *

Or specify allowed domain:

Access-Control-Allow-Origin: http://wordpress.local.host

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?

Community
  • 1
  • 1
Glavić
  • 42,781
  • 13
  • 77
  • 107
  • thanks for the answer. although i can detect post method with your suggestion, kohana doesn't keep the session, and i can't trace logged user any more, so i can't use this. in any other case this would probably be the solution. thanks for the effort and useful information! – markoc Jan 17 '13 at 10:33
  • and i can't give you +1 on answer, my rep is too low :) – markoc Jan 17 '13 at 10:54