【问题标题】:drupal 7 CORS localhost ajax requestdrupal 7 CORS localhost ajax请求
【发布时间】:2013-10-16 09:14:33
【问题描述】:

我试图从内部的本地文件中从 drupal 7 网站提取数据

http://example.com:8888/test/test.html

我使用这个带有 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 );

请帮助我告诉网站接受我的本地主机请求以从服务器中提取数据。相同的代码在纯 php 页面上测试并且工作正常。

【问题讨论】:

    标签: html jquery drupal-7 cross-domain cors


    【解决方案1】:

    不确定这有多安全,但解决它的一种方法是启用 CORS。

    1. 对于 Drupal 7(类似于 Drupal 6),因此您需要下载并安装 CORS 模块
    2. 启用Modules下的模块,
    3. 转到Drupal configConfiguration 在 Drupal 7 主仪表板顶部导航器上),
    4. 搜索 CORS。点击,
    5. 提供您希望访问的链接的路径。该页面上提供了如何添加新链接的示例。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-04-20
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2015-06-05
      • 2021-02-04
      • 2015-12-15
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多