以此为指导:http: //msdn.microsoft.com/en-us/library/dd250846.aspx
有人可以帮我打 jquery 电话吗?
我实际上是传入回调的javascript代码,还是只是函数的名称?
BingSearch = function($bingUrl, $bingAppID, $keyword, $callBack) {
$bingUrl = $bingUrl + "?JsonType=callback&JsonCallback=" + $callBack + "&Appid=" + $bingAppID + "&query=" + encodeURI($keyword) + "&sources=web";
$.ajax({
dataType: 'jsonp',
jsonp: $callBack,
url: $bingUrl,
success: function(data) {
alert('success');
$callBack(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("error: " + textStatus);
}
});
};
更新
好的,所以我将其更改为:
BingSearch = function(bingUrl, bingAppID, keyword, callback) {
var url = bingUrl + "?method=?&JsonType=callback&Appid=" + bingAppID + "&query=" + encodeURI(keyword) + "&sources=web";
$.getJSON(url, callback);
};
像这样称呼它:
BingSearch(url, appid, searchkeyword, function(searchresults) {
alert('yes!');
};
仍然收到“无效标签”错误。