?
Solved

how to use json in html cross domain

Posted on 2014-09-08
7
Medium Priority
?
15 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

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

Assisted Solution

by:Jim Riddles
Jim Riddles earned 1000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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