我该怎么办?$.加载到DIV和PHP头中以允许访问原点


How can I do? $.load into DIV and PHP header to allow access origin

我正在尝试将外部域URL加载到div中。这是我的代码:

<div id="content"></div>
<script>
$(document).ready(function() {
    $("#content").load("http://www.domain.com/external.php?query=sentence&callback=?");
});
</script>

在External.php的顶部,我放了:

<?php header("Access-Control-Allow-Origin: *");?>

但是我仍然看不到div中的内容。有什么问题吗?

你的例子对我来说很好。请记住,并非所有浏览器都支持跨域ajax调用。以下是列表