< !--导入JQ -->
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script>
$.ajax({
url: 'https://v2.api-m.com/api/color?color=#00ff88',
type: 'get',
beforeSend: function () {
//请求中执行的代码
},
complete: function () {
//请求完成执行的代码
},
error: function () {
//请求成功失败执行的代码
},
success: function (res) {
// 状态码 200 表示请求成功
if (res.code === 200) {
console.log(res)
} else {
console.log(res)
}
}
})
</script>
var axios = require('axios')
var config = {
method: 'get',
url: 'https://v2.api-m.com/api/color?color=#00ff88'
}
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
var requestOptions = {
method: 'GET',
redirect: 'follow'
}
fetch("https://v2.api-m.com/api/color?color=#00ff88", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error))
var xhr = new XMLHttpRequest()
xhr.withCredentials = true
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText)
}
})
xhr.open("GET", "https://v2.api-m.com/api/color?color=#00ff88")
xhr.send()
<? php
$curl = curl_init()
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://v2.api-m.com/api/color?color=#00ff88',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
))
$response = curl_exec($curl)
curl_close($curl);
echo $response
import requests
url = "https://v2.api-m.com/api/color?color=#00ff88"
payload = {}
headers = {
'User-Agent': 'xiaoxiaoapi/1.0.0 (https://api-m.com)'
}
response = requests.request("GET", url, headers = headers, data = payload)
print(response.text)