javascript - 前端进行API调用时,如何使用apikey。
阿神
阿神 2017-04-10 15:56:53
[JavaScript讨论组]

如图,已有apikey和地址。用jquery的ajax写,不知道如何添加apikey,所以一直提示missins apikey.
网上也找了很久,没有这方面的资料。

阿神
阿神

闭关修行中......

全部回复(4)
PHPz

文档里说了,apikey作为请求参数是放在header里传递的。
使用jquery的话可以查看官方文档添加header的方法:

$.ajax({
    url: '..',
    headers: {
        apikey: 'xxxx'
    }
})

headers (default: {})
Type: PlainObject
An object of additional header key/value pairs to send along with requests using the XMLHttpRequest transport. The header X-Requested-With: XMLHttpRequest is always added, but its default XMLHttpRequest value can be changed here. Values in the headers setting can also be overwritten from within the beforeSend function. (version added: 1.5)

而ip参数则正常地放在url Param里传递

PHP中文网

http://api.jquery.com/jquery.ajax/

data
Type: PlainObject or String or Array
Data to be sent to the
server. It is converted to a query string, if not already a string.
It's appended to the url for GET-requests. See processData option to
prevent this automatic processing. Object must be Key/Value pairs. If
value is an Array, jQuery serializes multiple values with same key
based on the value of the traditional setting (described below).

PHP中文网

在请求地址后面加上参数:
url?apikey=&ip=

天蓬老师

想知道不用jQuery用原生js能不能使用apikey,怎么使用?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号