我是Ajax请求的新手。我想发布到Metamind API,但它返回给我405错误。以下是教程中使用的Curl描述:http://docs.metamind.io/docs/image-classification,这是我的Ajax代码:
$.ajax({
url: "https://www.metamind.io/vision/classify",
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Authorization:","Basic <My_Authorization_Key>");},
dataType:"jsonp",
data: '{"classifier_id":"food-net",
"image_url":"https://www.metamind.io/static/images/classification-demo-examples/macarons.jpg"}'
})
非常感谢任何帮助
答案 0 :(得分:0)
此:
$.ajax({
method: "POST",
url: "https://www.metamind.io/vision/classify",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic yourkey");
},
data: '{"classifier_id":"food-net", "image_url":"https://www.metamind.io/static/images/classification-demo-examples/macarons.jpg"}',
success: function (msg) {
console.log("SUCCESS");
console.log(msg);
},
error: function (msg) {
console.log("FAIL");
console.log(msg.responseText);
}
});
对于那些喜欢AngularJS $ http:
的人$http.defaults.headers.common.Authorization = 'Basic yourkey';
$http({
method: "POST",
//data: '{"classifier_id":"food-net", "image_url":"http://www.ndtv.com/cooks/images/pizza-junk-food-600.jpg"}',
data: '{"classifier_id":"food-net", "image_url": "' + base64Img + '"}',
url: "https://www.metamind.io/vision/classify"
}).success(function (result) {
console.log("SUCCESS");
console.log(result);
}).error(function (err) {
console.log("FAIL");
console.log(err);
});