weixin_33701294 2016-07-29 13:10 采纳率: 0%
浏览 63

jQuery加载json数据

I have been trying to load some data from a json table using jQuery.

For some reason it's not working but I believe I had covered every aspect? I am hoping it is a syntax error that maybe has slipped through and not a total cock up from my part.

This is where I am at:

HTML:

<table id="fixtures">
  <thead>
    <tr>
      <th>Home</th>
      <th>Away</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

javascript:

var jsonDataUrl = 'http://bushell.net/football/site/includes/functions.php';

$(function() {
  $.ajax({
    type: 'GET',
    url: jsonDataUrl,
    async: false,
    jsonpCallback: 'JSON_CALLBACK',
    contentType: "application/json",
    dataType: 'json',
    success: function(data) {
      addRows($('#fixtures'), data, ['data.homeTeamName','data.awayTeamName']);
    },
    error: function(e) {
      console.log(e.message);
    }
  });
});

function addRows(table, data, fields) {
  var tbody = table.find('tbody');
  $.each(data, function(i, item) {
    tbody.append(addRow(item, fields));
  });
  return tbody;
}

function addRow(item, fields) {
  var row = $('<tr>');
  $.each(fields, function(i, field) {
    row.append($('<td>').html(item[field]));
  });
  return row;
}

Console Error:

(program):1 Uncaught SecurityError: Blocked a frame with origin "http://fiddle.jshell.net" from accessing a frame with origin "http://jsfiddle.net". Protocols, domains, and ports must match.(anonymous function) @ chrome-extension://geelfhphabnejjhdalkjhgipohgpdnoc/controllers/frame.js:1 jquery.min.js:4 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. jquery.min.js:4 XMLHttpRequest cannot load http://bushell.net/football/site/includes/functions.php. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.send @ jquery.min.js:4 (index):77 undefined (program):1 Uncaught SecurityError: Blocked a frame with origin "http://headwayapp.co" from accessing a frame with origin "http://jsfiddle.net". Protocols, domains, and ports must match.(anonymous function) @ chrome-extension://geelfhphabnejjhdalkjhgipohgpdnoc/controllers/frame.js:1 http://rum-collector.pingdom.net/img/beacon.gif?path=http%3A%2F%2Fjsfiddle.…&resE=1110&dL=1115&dI=3903&dCLES=3912&dCLEE=4361&dC=6421&lES=6421&lEE=6436 Failed to load resource: the server responded with a status of 522 (Origin Connection Time-out)

http://jsfiddle.net/XtzjZ/671/

  • 写回答

2条回答 默认 最新

  • weixin_33725239 2016-07-29 13:17
    关注

    You must have to set a header

    header("Access-Control-Allow-Origin: *");
    

    In your functions.php that's where you are requesting with Ajax.

    See this for more information:

    "No 'Access-Control-Allow-Origin' header is present on the requested resource"

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能