I want to get data from one of BLOCKCHAIN API....
But I get a small problem, where I want to access the API and inadvertently API BLOCKCHAIN using 'CORS HEADER' method, after I use 'AJAX GET REQUEST' anddddddd taraaaaaaa I get Error :).
in Controller 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');
}
}
in Asyc.js
$.getJSON( "https://blockchain.info/rawaddr/1N1WJYDUgaBrk9eUfawSYurs9ZtKcVVfTE", function( data ) {
console.log(data);
});
i got error
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.