验证比特币交易 Json

时间:2021-01-10 21:01:05

标签: ajax request payment bitcoin

我正在尝试使用示例请求验证我的应用程序的比特币 URL JSON 格式的交易。我不知道在这个 URL 中我是否有我的案例的答案。我需要在列表中显示数据。我需要的信息请求是付款没关系。你能帮我吗?

请求:https://blockchain.info/tx/a47b5f0e31faaec5ff7d8d7c4662e174dae99ecbddd9bf32a846017b69c98794?format=json

  $.ajax({
            url:'https://blockchain.info/tx/a47b5f0e31faaec5ff7d8d7c4662e174dae99ecbddd9bf32a846017b69c98794?format=json',
             type: 'POST',
             dataType: 'HTML',
             data: {param1: 'value1'},
         })
         .done(function(data) {
alert(data);
             console.log("success");
//check the json and print result
$('#answer').html("<li>"+data+"</li>");
         })
         .fail(function(data) {
alert("Error: " + data);
             console.log("error");
         })
         .always(function() {
             console.log("complete");
         });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <div id="answer">waiting..</div>

1 个答案:

答案 0 :(得分:0)

我想我理解你的问题,所以你想获取数据,然后将事务值列表打印到 DOM,所以我使用 fetch API 来检索事务值,然后我抓取了遍历它们的输出事务并创建了一个“li”对于每个值并将其附加到 DOM ,希望这对您有帮助

let proxyUrl = 'https://cors-anywhere.herokuapp.com/'

const list = document.getElementById('values')

const renderValues = (values) => {
 values.forEach(value => {
 const element = document.createElement('li')
 console.log(element)
 element.innerHTML = value.value
 list.appendChild(element)
 })
}
fetch(proxyUrl + 'https://blockchain.info/tx/a47b5f0e31faaec5ff7d8d7c4662e174dae99ecbddd9bf32a846017b69c98794?format=json').then(data => data.json()).then(res => renderValues(res.out)).catch(err => console.error(err))
    <div id="answer">
    <ul id="values">
    </ul>
    </div>