0

This is a very quick question.

Please refer this post.

Add header Access-Control-Allow-Origin to XMLHttpResponse in php

Where to add this code "header('Access-Control-Allow-Origin: *');"? I have same issues. Not sure where to add the code in the php script or javascript? Any help is appriciated.

I am creating a javascript widget for the other webmasters to consume. I have 2 javascripts and one php script. one javascript for the users to consume. That javascript calls the other one which makes the AJAX call and calls the PHP script which returns the json data.

I need the code sample.

Community
  • 1
  • 1
Raja
  • 23
  • 7
  • What have you tired? Hint: PHP. – RienNeVaPlu͢s Sep 07 '13 at 15:48
  • As far as I know you add the "header('Access-Control-Allow-Origin: *');" on the page you are calling with ajax. – Malcolm Sep 07 '13 at 15:51
  • Thanks Malcolm. I am creating a javascript widget for the other webmasters to consume. I have 2 javascripts and one php script. one javascript for the users to consume. That javascript calls the other one which makes the AJAX call and calls the PHP script which returns the jason data. So, i am thinking we can't ask the consumers to add this code. As the per the reference post Mahendra has added the code either in the php script or in the AJAX javascript. I may be wrong. – Raja Sep 07 '13 at 16:06
  • @RienNeVaPlus, thanks! Worked. Damn..! I already had the header code for the JASON. Just repeated the line. – Raja Sep 07 '13 at 16:16
  • http://stackoverflow.com/questions/18382740/cors-access-control-allow-origin-not-working-for-php kindly go through this link. I have specified the answer in here.. It worked for me. All the best... – Ganesh Babu Sep 07 '13 at 18:20
  • 1
    Thanks Ganesh. My headers is very generic now. I will go through the options and try to tight it little bit more. – Raja Sep 07 '13 at 18:49

0 Answers0