0

有什么方法可以在jQuery.getJSON不公开 api 密钥的情况下使用?例如,

jQuery.getJSON('http://example.com/api/{API_KEY}/word', function(data) {
  // ...
});

或者是在后端执行此任务的唯一方法?

4

1 回答 1

2

您可以使用 PHP 隐藏您的 api 密钥。创建something.php即:

<?php
    $data = file_get_contents('http://example.com/api/{API_KEY}/word');
    echo $data;
?>

PHP 在服务器端运行,因此客户端永远不会看到您的 api 密钥。只需使用本地文件,例如:

jQuery.getJSON('something.php', function(data) {
// ...
});
于 2015-10-19T02:56:40.273 回答