☰
Login
Signup
Home
›
Mobile and Desktop apps
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Register
Categories
Recent Discussions
Activity
Categories
12.5K
All Categories
100
Node JS client
35
Go client
741
.Net API client
345
Kite Publisher
528
.Net / VBA / Excel (3rd party)
411
Algorithms and Strategies
919
Java client
958
API clients
389
PHP client
3.5K
Python client
318
Mobile and Desktop apps
1.2K
Market data (WebSockets)
3K
General
In this Discussion
March 2016
Kailash
Unable to fetch data in webpage using http url in javascript. Error: Cross-Origin Request Blocked
vilassninawe
March 2016
edited March 2016
in
Mobile and Desktop apps
Hi,
I tried to fetch data for quote using below url from my webpage using javascript .
"
https://api.kite.trade/instruments/NSE/INFY?api_key=xxx&access_token=yyy
"
But I get below error.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
https://api.kite.trade/instruments/NSE/INFY?api_key=xxxxx&access_token=yyyyyyyyyyyyyy
. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Also, command given in developer page doesn't work when it is typed in linux terminal.
$ curl "
https://api.kite.trade/instruments/NSE/INFY?api_key=xxx&access_token=yyy
"
gives error {"status": "error", "message": "Missing access_token", "error_type": "InputException"}
It works only when I type it in firefox address bar.
How can I solve this problem.?
Below is the javascript used in my webpage:
var getInfo = function GetCustomerInfo()
{
var Url = "
https://api.kite.trade/instruments/NSE/INFY?api_key=xxxxx&access_token=yyyyyyyyyyyyyy
"
xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = ProcessRequest;
xmlHttp.open( "GET", Url, true );
xmlHttp.send( null );
}
function ProcessRequest()
{
if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
{
console.log( xmlHttp.responseText );
}
}
window.onload = getInfo;
Thanks.
Kailash
March 2016
As the error suggests, cross origin requests are blocked. You cannot make these requests from a webpage (browser) as that'll mean you expose the access_token. You have to access the API using a server side program.
Sign In
or
Register
to comment.