473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

JQ/CodeIgniter App: CORS header 'Access-Control-Allow-Origin' does not match *

228 New Member
Hey Fellas,

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
  1.  public function __construct(){
  2.  
  3. header("Access-Control-Allow-Origin: domainb.com");
  4. header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, XKMS,delayi");
  5. header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  6.  
  7. }
And in one of my methods, I do check the call is indeed ajax:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function itemchecker() {
  3.  
  4.     $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
  5.  
  6. if ($ajax) {
  7.   // handle specific Ajax differently...
  8.  echo "ajax called";
  9. //accept posted items and process now
  10. }
  11.  
  12.     }    
  13.  
  14.  
In domainb i have:

Expand|Select|Wrap|Line Numbers
  1.  var postForm = {'e':851470}; //Fetch form data
  2.  
  3.  
  4.  
  5.        $.ajax({
  6.                 type: "POST",
  7.                 url: "http://domaina.com/check/itemchecker/",
  8.  
  9.                 data: postForm,
  10.                 dataType : "text",
  11.  
  12.                 cache: "false",
  13.     contentType: "application/x-www-form-urlencoded",
  14.                 success: function (result) {
  15.  
  16.  
  17.                     alert(result);
  18.                 },
  19.                 fail: function (result){
  20.                 alert(result);
  21.                 }
  22.  
  23.  
  24.             });
  25.  
  26.  
  27.  
The exact error message I am getting now is:

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?
Jul 12 '16 #1
1 4248
gits
5,390 Recognized Expert Moderator Expert
u might check what the jQuery request is sending as headers (for example in the chrome or firefox dev tools) - and try to set the:

Expand|Select|Wrap|Line Numbers
  1. Access-Control-Request-Method
  2. Access-Control-Request-Headers
headers explicitly for the request.
Jul 13 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: gsb | last post by:
I need to link one of several JavaScript files into an application. I'm using php to pick the file and "pass it thru" (passthru) based on http_get_vars. What is the header I need to send? ...
6
by: Duane Morin | last post by:
I've inherited an XSL transform that I need to squeeze every last millisecond out of (since it's running several hundred thousand times). I've noticed that there are 26 match clauses in the file....
3
by: sapsi | last post by:
Hi, I managed to create a python class and instantiate that from my Objective C Cocoa App (its not a python app). Essentially, i made two classes in IB and then another class(ogle) with outlets...
4
by: liyanage | last post by:
I recently worked on error handling and three related issues/questions came up. 1.) I am trying to trigger Apache ErrorDocument handlers by setting appropriate HTTP status codes in my PHP...
6
by: lawrence k | last post by:
Wierd. Go to this page: http://www.ihanuman.com/search.php and search for "yoga" This query gets run: SELECT * FROM albums WHERE MATCH(name,description) AGAINST ('yoga') ORDER BY id DESC
19
by: pmw | last post by:
Hi I've got a problem with my current application. I currently use Windows Vista with Visual Studio Express 2008. If I compile the application on Vista, it works fine on Vista, but it doesn't...
5
by: sarah89 | last post by:
hello ^^ i used header in my codes, and it was working fine in the local server. but when i upload it to the public server i keep get the following error: Warning: Cannot modify header...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.