Author

Topic: Blockchain AJAX Request (Read 2114 times)

hero member
Activity: 532
Merit: 500
September 14, 2013, 09:09:39 PM
#10
Okay I understand thanks for the help guys. ^^
legendary
Activity: 3612
Merit: 1564
September 13, 2013, 08:36:06 PM
#9
I appreciate your help buddy, but that is exactly what I want to prevent. If I do it this way my server will make that query everytime somebody triggers the script.

No. You split up the data fetching php script and the ajax query handling PHP script. The data fetching part gets executed every x minutes via a cron job. It saves the data to the database. The ajax query handling part merely reads the data from the db and relays it back to the client. This is how I do it on my site.
sr. member
Activity: 516
Merit: 283
September 13, 2013, 10:14:29 AM
#8
the server is probably configured to allow xss, whereas blockchain isnt. its a configuration in apache/nginx/whatever http server being used
Okay so as far as I understand, blockchain has this very sweet api where I can get all kind of information, but I am not allowed to use it in javascript, right?

not without a middleman (the php script)
hero member
Activity: 532
Merit: 500
September 13, 2013, 10:12:06 AM
#7
the server is probably configured to allow xss, whereas blockchain isnt. its a configuration in apache/nginx/whatever http server being used
Okay so as far as I understand, blockchain has this very sweet api where I can get all kind of information, but I am not allowed to use it in javascript, right?
hero member
Activity: 574
Merit: 500
Mining for the hell of it.
September 13, 2013, 01:50:27 AM
#6
mtgox has a api already out.
sr. member
Activity: 516
Merit: 283
September 13, 2013, 12:39:20 AM
#5
the server is probably configured to allow xss, whereas blockchain isnt. its a configuration in apache/nginx/whatever http server being used
hero member
Activity: 532
Merit: 500
September 12, 2013, 11:56:48 PM
#4
you need a php script that does a simple curl request towards GOX api. Something like this:

Code:
$url "http://whateverapi.com/you/want/to/query.php";
$ch curl_init($url);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_BINARYTRANSFERtrue);
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
curl_setopt($chCURLOPT_HTTPHEADER, array('Host: whateverapi.com'));
$output curl_exec($ch);
curl_close($ch);
echo 
$output;
?>


then you make an ajax call to that script, and make sure they're on the same domain to avoid xss.

i have this exact setup running on my server here for my own personal ticker: http://samad64.com/coin/

goes without saying, you need curl support on your server.

I appreciate your help buddy, but that is exactly what I want to prevent. If I do it this way my server will make that query everytime somebody triggers the script. I think my IP would be blocked by MtGox in notime if I would do it this way. I would need to check when it received data the last time, so it would connect to blockchain like at max every 10 or 15 seconds. Instead I want the user to connect to blockchain, which can be done pretty easy in javascript.(at leat I thought) I really don´t want to use php for this one. I want rather understand why I can get data with AJAX from MtGox and why it fails to get data from blockchain.
sr. member
Activity: 516
Merit: 283
September 12, 2013, 11:42:04 PM
#3
you need a php script that does a simple curl request towards blockchain api. Something like this:

Code:
$url "http://whateverapi.com/you/want/to/query.php";
$ch curl_init($url);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_BINARYTRANSFERtrue);
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
curl_setopt($chCURLOPT_HTTPHEADER, array('Host: whateverapi.com'));
$output curl_exec($ch);
curl_close($ch);
echo 
$output;
?>


then you make an ajax call to that script, and make sure they're on the same domain to avoid xss. be sure to include any auth tokens that are required by the api

i have this exact setup running on my server for my own personal ticker. ajax request to local php script which queries an API, updating ticker values.

goes without saying, you need curl support on your server.
hero member
Activity: 532
Merit: 500
September 12, 2013, 11:29:10 PM
#2
Meeeh, I was trying to avoid that. It is much more work... I would need to set database entries and look when the data was last checked so I don´t send data to blockchain.info everytime a user clicks on my site... A nice little javascript would let the user check the current values. I think that would be way better concerning live data and also my server wouldn´t need to check the data, which could cause the site to load slower when the script gets triggered. But I guess you also don´t have a solution to my javascript problem?(if there is any)
Maybe you know if it is Blockchain.info that does not want to respond to javascripts or is it the javascript that does not want to connenct to blockchain.
I analyzed the traffic in firefox and it shows that I´m actually sending the data and getting a response, but the response are only headers and no data...
So if this "same Origin" policy is there for security reasons like preventing XSS, then it is not doing its job, right? Cuz it sends data to the server anyway. I have not tested how far this policy goes and if it is possible to send cookies or something like that.
Also it works for MtGox to receive data from the server. If the address is like "http://something.something.com/xyz"(like it is when using the gox api) it seems to work. If the address is like "http://something.com/xyz" it does not work? Also I can get data from Blockchain.info when I open the html file with the script in it with the Internet Explorer from a file(file://xyz.html), but when I do it with a server running(localhost/xyz.html) it does not work... In Firefox it doesn´t work at all. WTF?! I couldn´t find a solution to this problem, but I´m sure I´m not the first one that has this problem. Any help is appreciated. This stuff is really driving me mad!!!  Angry
hero member
Activity: 532
Merit: 500
September 12, 2013, 08:05:47 PM
#1
Hi Guys,

I'm trying to do a request on the blockchain.info api using ajax. for some reason I am getting a response with no data in it. I'm trying the same on MtGox and it works. I think it has to do with the "same Origin" policy in ajax. can somebody help me with this issue or knows a good workaround?
If necessary I can post the code here...
Jump to: