Jquery Ajax API Error: 400 Bad Request
Jquery Ajax API Error: 400 Bad Request
我正在尝试使用 Jquery 向名为 Cloudsight 的图像识别 API 发出 Ajax POST 请求。到目前为止我的代码是:
$.ajax({
type: "POST",
url: "http://api.cloudsightapi.com/image_requests",
Authorization: "CloudSight [key]",
data: {
remote_image_url: "https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
locale: "en-US"
},
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
当我尝试 运行 它时,我收到错误:400(错误请求)我做错了什么?据我所见,代码似乎没问题...
你试过这样的东西吗?
beforeSend: function (req){
req.setRequestHeader("Authorization", "CloudSight [key]");
},
万一其他人看到这个,设法用这个代码解决问题:
$.ajax({
method: "POST",
url: "https://api.cloudsightapi.com/image_requests",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "CloudSight [key]");
},
data: {
"image_request[remote_image_url]": "https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
"image_request[locale]": "en-US"
},
success: function(msg) {
console.log("It worked! :D Good POST request.");
console.log(msg);
console.log(msg.token);
console.log(msg.url);
console.log(msg.responseText);
token = msg.token;
},
error: function(msg) {
console.log("Sorry...");
console.log(msg);
console.log(msg.responseText);
}
});
感谢 Mario Cezar 协助授权!
我正在尝试使用 Jquery 向名为 Cloudsight 的图像识别 API 发出 Ajax POST 请求。到目前为止我的代码是:
$.ajax({
type: "POST",
url: "http://api.cloudsightapi.com/image_requests",
Authorization: "CloudSight [key]",
data: {
remote_image_url: "https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
locale: "en-US"
},
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
当我尝试 运行 它时,我收到错误:400(错误请求)我做错了什么?据我所见,代码似乎没问题...
你试过这样的东西吗?
beforeSend: function (req){
req.setRequestHeader("Authorization", "CloudSight [key]");
},
万一其他人看到这个,设法用这个代码解决问题:
$.ajax({
method: "POST",
url: "https://api.cloudsightapi.com/image_requests",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "CloudSight [key]");
},
data: {
"image_request[remote_image_url]": "https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
"image_request[locale]": "en-US"
},
success: function(msg) {
console.log("It worked! :D Good POST request.");
console.log(msg);
console.log(msg.token);
console.log(msg.url);
console.log(msg.responseText);
token = msg.token;
},
error: function(msg) {
console.log("Sorry...");
console.log(msg);
console.log(msg.responseText);
}
});
感谢 Mario Cezar 协助授权!