[英]jQuery jsonp hide api key
Is there any way to use jQuery.getJSON
without making the api key public? 有没有办法使用
jQuery.getJSON
而不公开api键? For example, 例如,
jQuery.getJSON('http://example.com/api/{API_KEY}/word', function(data) {
// ...
});
Or is the only way to do this task on the backend? 或者是在后端执行此任务的唯一方法?
You can hide your api key with PHP. 你可以用PHP隐藏你的api密钥。 Create
something.php
that is: 创建
something.php
即:
<?php
$data = file_get_contents('http://example.com/api/{API_KEY}/word');
echo $data;
?>
The PHP runs server-side, so the client never sees your api key. PHP在服务器端运行,因此客户端永远不会看到您的api密钥。 Just use the local file such as:
只需使用本地文件,例如:
jQuery.getJSON('something.php', function(data) {
// ...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.