Solved

how to use json in html cross domain

Posted on 2014-09-08
7
13 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 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
Stressed Out?

Watch some penguins on the livecam!

 
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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

705 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