Html drupal 7 CORS本地主机ajax请求

Html drupal 7 CORS本地主机ajax请求,html,jquery,drupal-7,cross-domain,cors,Html,Jquery,Drupal 7,Cross Domain,Cors,我试图从Drupal7网站的本地文件中提取数据 我在html请求中使用了这个Ajax代码,因为我已经尝试了json,而且即使我添加了 <?php header('Access-Control-Allow-Origin: *'); ?> 代码以提取数据,但没有结果: $.ajax( { // The link we are accessing. url: "http://horizon-websolutions.com", // The ty

我试图从Drupal7网站的本地文件中提取数据

我在html请求中使用了这个Ajax代码,因为我已经尝试了json,而且即使我添加了

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

代码以提取数据,但没有结果:

 $.ajax(
    {
    // The link we are accessing.
    url: "http://horizon-websolutions.com",

    // The type of request.
    type: "get",

    // The type of data that is getting returned.
    dataType: "html",

    error: function(){
    alert("error");
    // Load the content in to the page.
    $("#output").html( "<p>Page Not Found!!</p>" );
    },

    beforeSend: function(){
    alert("not yet"); },

    complete: function(){
    alert("done"); },

    success: function( strData ){
    alert("success");
    // Load the content in to the page.
    $("#output").html( strData );
    }
    }
    );

    // Prevent default click.
    return( false );
$.ajax(
{
//我们正在访问的链接。
url:“http://horizon-websolutions.com",
//请求的类型。
键入:“获取”,
//返回的数据类型。
数据类型:“html”,
错误:函数(){
警报(“错误”);
//将内容加载到页面中。
$(“#输出”).html(“找不到页面!!

”; }, beforeSend:function(){ 警惕(“尚未”);}, 完成:函数(){ 警报(“完成”);}, 成功:函数(strData){ 警惕(“成功”); //将内容加载到页面中。 $(“#输出”).html(标准数据); } } ); //防止默认单击。 返回(假);

请帮助我告诉网站接受我的localhost请求,以便从服务器提取数据。相同的代码在纯php页面上进行了测试,并且运行良好。

不确定这是否安全,但解决这一问题的一种方法是启用CORS

  • 对于Drupal 7(类似于Drupal 6),您需要下载并安装CORS模块
  • 启用模块下的模块
  • 转到Drupal 7主仪表板顶部导航器上的Drupal配置(配置)
  • 搜索CORS。点击
  • 提供您希望访问的链接的路径。该页给出了如何添加新链接的示例
  • 希望这有帮助