Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  38] [ 1]  / answers: 1 / hits: 26460  / 11 Years ago, wed, april 10, 2013, 12:00:00

I want to make a page on domain example1.com and get/parse a JSON file on another domain example2.com/json.json. Can the json file be generated with javascript (on example2.com)? I think this can be done with php, but I want to do it with javascript. If it is not possible to generate a json file with javascript, is it possible to get/parse an object from a javascript file? EX: example1.com to example2.com/js.js



EDIT: Ok, so it is not possible to get/parse an object from a javascript file, because it is client side. So my only option is to generate a JSON file. Is it possible to do that with Javascript? I know it's probably not the best way, but I want to do it in JS, not PHP.


More From » jquery

 Answers
30

To parse a JSON object with Javascript, I would use jQuery.


http://api.jquery.com/jQuery.parseJSON/



Like anthonybell said most browsers do not allow cross-site scripting so you need to look into jsonP or work on the same domain.



Also to generate JSON you can create an object using javascript then either loop though it and output it or just output your data in JSON format which you can read about here:

http://www.w3schools.com/json/


[#79005] Monday, April 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;