将CORS添加到嵌入式API请求中

时间:2016-10-07 19:36:12

标签: jquery json ajax api

使用相同的域时,这似乎有效http://citrowske.com/jsontest.html。但是当我尝试将它放在域外的任何地方时(即使包含整个JSON文件URL),当"加载数据"单击按钮。

     <head>
  <title>The jQuery Example</title>
  <script type = "text/javascript" 
     src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script type = "text/javascript" language = "javascript">
     $(document).ready(function() {
        $("#driver").click(function(event){
           $.getJSON('http://citrowske.com/help2.json', function(jd) {
              $('#stage').html('<p> Id: ' + jd.Id + '</p>');
              $('#stage').append('<p> UserName : ' + jd.UserName+ '</p>');
              $('#stage').append('<p> FirstName: ' + jd.FirstName+ '</p>');
              $('#stage').append('<p> LastName: ' + jd.LastName+ '</p>');
              $('#stage').append('<p> Active: ' + jd.Active+ '</p>');
              $('#stage').append('<p> Email: ' + jd.Email+ '</p>');
              $('#stage').append('<p> AccessLevel: ' + jd.AccessLevel+ '</p>');
           });
        });
     });
  </script>

json源位于:http://citrowske.com/help2.json

我认为它必须是因为交叉起源,但不能在如何将CORS纳入此程序中做出正面或反面。

非常感谢任何帮助!

0 个答案:

没有答案