【问题标题】:How to use onclick button to request php api如何使用onclick按钮请求php api
【发布时间】:2019-05-24 22:22:16
【问题描述】:

$response = Unirest\Request::get("https://cometari-airportsfinder-v1.p.rapidapi.com/api/airports/by-radius?radius=50&lng=-157.895277&lat=21.265600", 大批( "X-RapidAPI-Host" => "cometari-airportsfinder-v1.p.rapidapi.com", "X-RapidAPI-Key" => "xxxx" ) );

【问题讨论】:

  • 这个问题没有显示任何研究工作;不清楚或没用。
  • 感谢 Robert Columbia 的回复。将来,我将确保该问题确实显示了研究工作。 API 对我来说是新的。此外,世界上许多专业人士都有心和正直的教诲他人。所以,它就变成了一种非凡的体验。

标签: php


【解决方案1】:

这对我有用,并将结果显示在一个 div 中。

HTML

<html>
    <head>
        <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    </head>
    <body>
        <button type="button" onclick="$.get('/ajax-rapidapi.php', function(result) { $('#result').html(result); });">Click Me!</button>
        <div id="result"></div>
    </body>
</html>

PHP (ajax-rapidapi.php)

<?php

die(Unirest\Request::get("https://cometari-airportsfinder-v1.p.rapidapi.com/api/airports/by-radius?radius=50&lng=-157.895277&lat=21.265600", array( "X-RapidAPI-Host" => "cometari-airportsfinder-v1.p.rapidapi.com", "X-RapidAPI-Key" => "02f2e99835msh60df6f30e23585dp137d84jsn437639993023")));

【讨论】:

    猜你喜欢
    • 2012-11-28
    • 1970-01-01
    • 2018-08-23
    • 2017-11-04
    • 2013-04-03
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多