I am seriously in despair. I have a CI driven app in domaina.com. I need to send cross domain request to a SINGLE controller in it from domainb.com. It will be an ajax call using POST method. It sends a single number and get a text reply from domaina.com.
htaccess is not really an option as I only call a single controller domaina.com/check (then a couple of methods in check controller). Here is what I have until now:
Expand|Select|Wrap|Line Numbers
- public function __construct(){
- header("Access-Control-Allow-Origin: domainb.com");
- header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, XKMS,delayi");
- header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
- }
Expand|Select|Wrap|Line Numbers
- function itemchecker() {
- $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
- if ($ajax) {
- // handle specific Ajax differently...
- echo "ajax called";
- //accept posted items and process now
- }
- }
Expand|Select|Wrap|Line Numbers
- var postForm = {'e':851470}; //Fetch form data
- $.ajax({
- type: "POST",
- url: "http://domaina.com/check/itemchecker/",
- data: postForm,
- dataType : "text",
- cache: "false",
- contentType: "application/x-www-form-urlencoded",
- success: function (result) {
- alert(result);
- },
- fail: function (result){
- alert(result);
- }
- });
Reason: CORS header 'Access-Control-Allow-Origin' does not match domainb.com
yet, i am on domainb.com. I did try adding http://domainb.com, domainb.com,domaib.com/page/action (which sends the request). Am really lost whats going on.
Any insight?