Solved

how to use json in html cross domain

Posted on 2014-09-08
7
10 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 4

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
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)

786 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