0

I have two websites namely:

www.siteone.com 
www.sitetwo.com

Now I have to display data in www.siteone.com by getting data via script from www.sitetwo.com Since I have to get particular data, I am passing variable from www.siteone.com to www.sitetwo.com like this:

 //script in www.siteone.com
<script type="text/javascript">
    $(document).ready(function(){
        window.$vars = {
            id:"form"
        };
</script>

In www.sitetwo.com, I have the following script:

//script in www.sitetwo.com
<script type="text/javascript">
 var k = window.$vars.id;
$("#form").dform("http://www.sitetwo.com/"+k+'.json', function(data) {

          this
          data

        });
</script>

Here the value "id" that I am passing from siteone to site two is received by the script correctly. But I cannot open form.json file due to crossdomain. The following error is thrown:

XMLHttpRequest cannot load http://www.sitetwo.com/form.json. Origin http://www.siteone.com is not allowed by Access-Control-Allow-Origin.

How can I access form.json from www.siteone.com

Ganesh Babu
  • 3,590
  • 11
  • 34
  • 67
  • jsonp is the answer. You need to find a way to use jsonp with that `dform` ajax call. – SachinGutte Aug 21 '13 at 11:06
  • dform is a function from another script loaded in that page.How can we effectively use jsonp in these cases?? – Ganesh Babu Aug 21 '13 at 11:08
  • i haven't used that dform script. With jquery ajax you can easily use jsonp by setting dataType to jsonp. – SachinGutte Aug 21 '13 at 11:18
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin Aug 21 '13 at 11:28

2 Answers2

1

YOu can send an additional header from server side script.

header("Access-Control-Allow-Origin: http://www.sitetwo.com");

Access-Control-Allow-Origin Multiple Origin Domains?

Community
  • 1
  • 1
Roseann Solano
  • 762
  • 2
  • 8
  • 13
0

Browser standarts does not allow you to load JSON from another domain because of same-origin policy. Use JSONP

Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79