【发布时间】:2016-07-23 02:21:41
【问题描述】:
我正在尝试使用图像搜索 API,但没有得到搜索结果。 这是我在同一页文档中找到的代码。
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
// Request parameters
"q": "cats",
"count": "10",
"offset": "0",
"mkt": "en-us",
"safeSearch": "Moderate",
};
$.ajax({
url: "https://api.cognitive.microsoft.com/bing/v5.0/images/search?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","MYKEY");
},
type: "GET",
// Request body
data: "{body}",
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
我真的很想做图片搜索,有了这个 API 就可以为我服务了。
【问题讨论】:
-
data: "{body}"看起来不正确 - 您是否有指向您获取此代码的页面的链接? -
url 是 [link]dev.cognitive.microsoft.com/docs/services/… [/link] 我尝试使用ˋconsole.log(data)ˋ 没有结果
-
奇怪你在除 C# 之外的所有语言中都需要这个
"{body}"...控制台上的任何错误或消息
标签: javascript ajax bing