に私はBLOCKCHAINのAPIのいずれかからデータを取得したい....なぜ、アクセス制御 - 許可 - 起源が動作しない、CodeIgniterの残り-サーバー
しかし、私は、私の小さな問題を取得私は 'AJAX GET REQUEST'を使って、CORS HEADERメソッドを使用してAPIと誤ってAPI BLOCKCHAINにアクセスしたいと思っています。 Asyc.js
$.getJSON("https://blockchain.info/rawaddr/1N1WJYDUgaBrk9eUfawSYurs9ZtKcVVfTE", function(data) {
console.log(data);
});
で
コントローラCart.phpで<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Cart extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
header("Access-Control-Allow-Methods: GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding");
if ("OPTIONS" === $_SERVER['REQUEST_METHOD']) {
die();
}
}
public function index()
{
$this->load->view('cart_view');
}
}
私はあなたがCORSがどのように機能するかを誤解しましたエラー
XMLHttpRequest cannot load https://blockchain.info/rawaddr/1N1WJYDUgaBrk9eUfawSYurs9ZtKcVVfTE. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
'Controller Cart.php'は' https:// blockchain.info/rawaddr/1N1WJYDUgaBrk9eUfawSYurs9ZtKcVVfTE'や 'http:// localhost'を生成するファイルですか? – Quentin