0

So, I know this question has been answered a lot of times already (I've tried the answers of some of them) but I just can't get it to work!

I am trying to get the json from http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=1739 get the item.current.price data. Because this updates every day, I can't download the json and use it locally.

I've tried JSONP, $.ajax, CORS, all kinds of stuff! If someone could help me do this in javascript, it would be highly appreciated.

Astavie
  • 91
  • 1
  • 8
  • "I do have a feeling I have to use CORS somehow" — No, the site you are requesting the data from has to use CORS. You can't give your site permission to use your visitors' browsers to read data from other sites. – Quentin Dec 09 '15 at 20:07
  • it is an old trope, but true -- you should probably just do this in jQuery. – Hogan Dec 09 '15 at 20:07
  • The server in question needs to allow CORS by setting a header on their responses. They have not set that header. Therefore it is probably impossible to do this from the browser -- you'll need to make a request from a server. (FWIW they're also failing to set the right content-type header on their response, possibly creating a security vulnerability for their users in certain contexts.) – Jeremy Dec 09 '15 at 20:07
  • 1
    @Hogan — jQuery won't help with the problem at all … and the question says they tried `$.ajax` already. – Quentin Dec 09 '15 at 20:08
  • @Quentin Ok, then I have no idea how CORS work XD – Astavie Dec 09 '15 at 20:08
  • @Hogan like quentin said, that doesnt fix the cross-domain issue – Astavie Dec 09 '15 at 20:09
  • @Quentin - `$.ajax` means jQuery? Ok, learn something new every day. – Hogan Dec 09 '15 at 20:09
  • @Hogan — `$` is the standard shorthand variable name for jQuery. Other libraries use the same variable name, but they tend not to have a `ajax` property. – Quentin Dec 09 '15 at 20:10
  • @Quentin if you were the one that said the answer was in http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy: I looked through it, but I didn't understand much of it. I am a person that can learn alot by looking at code, but the answers there were more gibberish than code. – Astavie Dec 09 '15 at 20:14
  • @TheRActivator The web security model (CORS) does not provide any way to do this without controlling the source server. There is no code that can get around this fact. You'll need to wrap your head around the gibberish if you want to get anywhere. Those answers all assume you control the source server. If you don't, you'll need to run your own server to relay the data. – Jeremy Dec 09 '15 at 23:02

0 Answers0