drupal 7 CORS本地主机ajax请求 [英] drupal 7 CORS localhost ajax request

查看:643
本文介绍了drupal 7 CORS本地主机ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从drupal 7网站从本地文件中获取数据

im trying to pull data from drupal 7 website from a local files inside

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

我使用这个Ajax代码与HTML请求,因为我已经尝试json,并且该网站阻止我拉,即使我已经添加了

im using this Ajax code with html request since i have tried json and also the website prevents me from pulling even i have added

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

代码拉数据,但没有结果:

code to pull the data , but no result:

 $.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页面上进行测试,其工作正常。

please help my telling the website accept my localhost request to pull data from the server . the same code tested on a pure php page and its working fine .

推荐答案

不知道这是多么安全,但是一种方法解决它是启用CORS。

Not sure how secure this would be but one way to solve it is to enable CORS.


  1. 对于Drupal 7(将类似于Drupal 6),因此您需要下载并安装 CORS模块

  2. 启用模块下的模块,

  3. 转到 Drupal配置配置在Drupal 7主仪表板顶部导航器上),

  4. 搜索 CORS 。点击

  5. 给出您要访问的链接的路径。

  1. For Drupal 7 (would be analogous to Drupal 6) so you need to download and install the CORS module,
  2. enable the module under Modules,
  3. go to the Drupal config (Configuration on Drupal 7 main dashboard top navigator),
  4. search for CORS. Click,
  5. give the path for the links you wish to access. Examples are given on that page of how to put in new links.

希望这有帮助。

这篇关于drupal 7 CORS本地主机ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆