0

In my web site (hosted here), I have a JSON string that I'm unable to parse in HTML using this function:

<script>
 function check(){
      var url="https://www.cs.bgu.ac.il/~elii/j.json";
      $.get(url)
    // If the AJAX call was successful, let's process that data!
    .done( function(data) {
        alert("success");

        }) 
        .fail( function() {
      alert("Sorry, something went wrong!")
      });
    }
 </script>

However, if I change the URL to be

http://www.omdbapi.com/?t=homeland&y=&plot=short&r=json

the function succeeds even though it has the same content as my website.

Can someone tell me why this happens?

joe
  • 2,468
  • 2
  • 12
  • 19
  • So, is the call failing - i.e. the alert is being displayed that reads "Sorry, something went wrong!"? This could be to do with the first site not allowing cross-site requests: http://stackoverflow.com/questions/6871021/how-to-enable-cross-domain-request-on-the-server – Callan Heard Jun 29 '16 at 15:45
  • no, nothing is happening. it's not failing... the fail alert not happens. – user6529259 Jun 29 '16 at 15:47
  • Where are you invoking this function? – Teemu Jun 29 '16 at 15:48
  • html. on my computer. the most regular page html... it just have a button that calling this func – user6529259 Jun 29 '16 at 15:49
  • 1
    It works for me.. http://output.jsbin.com/qizibet. The error shows because of cross domain ajax request. – Mosh Feu Jun 29 '16 at 15:52
  • Also, the second URL returns `Access-Control-Allow-Origin:*` header, you don't. – Mosh Feu Jun 29 '16 at 15:54
  • 1
    oh thanks. where i should put this "Access-Control-Allow-Origin:*"? in the head of the website? or the head calling html page? – user6529259 Jun 29 '16 at 15:58
  • my friend just told me it has something todo with that my website is https and not usual http? what do you think? – user6529259 Jun 29 '16 at 16:29
  • The server that serves the JSON needs to grant your site access (unlikely). – Ben Jun 29 '16 at 18:06

0 Answers0