gpt4 book ai didi

jquery - 使用ajax Jquery调用API

转载 作者:行者123 更新时间:2023-12-01 08:33:57 24 4
gpt4 key购买 nike

我有请求

$(function(){
$.ajax({
type: 'GET',
dataType:"jsonp",
url: "http://localhost:8000/api/admin/announces",
headers:{
'Authorization' : 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBWZXIiOiIwLjAuMCIsImV4cCI6NDcyNjM4OTEyMiwibG9jYWxlIjoiIiwibWFzdGVyVmVyIjoiIiwicGxhdGZvcm0iOiIiLCJwbGF0Zm9ybVZlciI6IiIsInVzZXJJZCI6IiJ9.QIZbmB5_9Xlap_gDhjETfMI6EAmR15yBtIQkWFWJkrg',
'Content-Type':'application/json'
},
succces: function(data){
console.log('success',data);
}
});
});

我有 400 错误请求错误 net::ERR_ABORTED 400(错误请求)。我缺少什么?

最佳答案

您只需将 URL 替换为本地 REST API:

$.ajax({
type: 'GET',
dataType:"jsonp",
url: 'https://jsonplaceholder.typicode.com/todos/1',
headers:{
'Authorization' : 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBWZXIiOiIwLjAuMCIsImV4cCI6NDcyNjM4OTEyMiwibG9jYWxlIjoiIiwibWFzdGVyVmVyIjoiIiwicGxhdGZvcm0iOiIiLCJwbGF0Zm9ybVZlciI6IiIsInVzZXJJZCI6IiJ9.QIZbmB5_9Xlap_gDhjETfMI6EAmR15yBtIQkWFWJkrg',

},
success: function (data, status, xhr) {
console.log('data: ', data);
}
});

关于jquery - 使用ajax Jquery调用API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59028103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com