Solved

how to use json in html cross domain

Posted on 2014-09-08
7
11 Views
Last Modified: 2016-05-18
whats the bast way to access json text files cross domain using jquery hopefully with an example
thanks geoff
0
Comment
Question by:hyperaccess
  • 3
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40310733
With jquery ?
You can't really, you need help of a server to create a proxy.
So this server/proxy load the content for you
0
 

Author Comment

by:hyperaccess
ID: 40310740
what about using java ajax or using pjson
thanks geoff
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 40310746
what is java ajax?
if you're talking about jsonp, you can only load a javascript script with.
<script>functionname({"text":"your file text content in this string"})</script>

If you are able to send this with te right content-type application/json you're done else forget it
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:hyperaccess
ID: 40310763
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40310765
yes this is what I'm yalked about in my previous post
0
 
LVL 5

Assisted Solution

by:Jim Riddles
Jim Riddles earned 250 total points
ID: 40312192
You can also set your script that returns your JSON data to set the access-control-allow-origin header.  With that set you can allow a page on a different domain to access your data.

In PHP you would add something like this to the top of your script:

header('Content-type: application/json');
header('access-control-allow-origin: http://yoursite.com');
header('access-control-allow-origin: https://subdomain.yoursite.com');

Open in new window


Replace the URLs with the domains that you want to allow access to the data.  Note: You may see examples that show an * in place of the URL...never use it, since it allows access from any host.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question