Parsing the json and storing it in an array?
i'm very new to this web related problems, please help
i'm working on sencha which proves to be very difficult wen it comes to json parsing . . . .
so i'm planning on retrieving the data to the html page and then load it into my js file. . .
so here is the problem:
i've already asked about it and got a reply..
http://jsbin.com/uwuca5
but now wen i use the html source code locally in my system or even by using the IIS i couldn't parse the data. . . . . . .
here is the link for my json file:
http://compliantbox.com/optionsedge/sample.php
i'm trying to use this link in my code and retrive the data but the data is returning null
Please Hel开发者_JAVA技巧p
Thank you,
You may be running into the Same Origin Policy. Are you trying to retrieve the data from a different "origin"? For instance, when running locally on IIS (ajax stuff mostly doesn't work unless you're using a server), are you trying to reach out to http://compliantbox.com/optionsedge/sample.php
to get the data? If so, that won't work in most cases (see the link for why). For instance, if I modify the JSBin code I gave you in my previous answer to use http://compliantbox.com/optionsedge/sample.php
instead of http://jsbin.com/uwura4
, it fails (example).
Cross-origin calls are possible, but you largely have to be in charge of both sides of the call for them to work. There's CORS (requiring special headers from the server, and support in the browser that's missing in IE6 and IE7; it's in IE8 but you have to use an XDomainRequest
instead of an XMLHttpRequest
), and there's JSON-P (requiring the source to support JSON-P explicitly).
I'm not familiar with Sencha, but it seems that you're trying to make a cross-domain AJAX call (calling the url http://compliantbox.com/optionsedge/sample.php from within another domain, e.g. from within your local web-site) which is basically not allowed (at least by using XmlHTTPRequest object).
I'd suggest you to take a look at these posts:
- Forum post on jQuery web-site
- The jQuery cross-domain AJAX guide
-- Pavel
If you need read the JSON from a different domain you can try first read the document from your server and serve it.
Jquery:
$.getJson("Url-in-your-domain");
Url-in-your-domain: Read the remote document and serve it.
Try if you don't find any solution.
精彩评论