我和你有同样的问题!我GOOGLE了,并找到一些解决方案 ,我已经解决了我的问题。现在我给你看,我希望它可以帮助你:)
以前的代码:
function MakeGeocodeRequest(credentials) {
var pins = checkLocation.d
$.each(pins, function (index, pin) {
var geocodeRequest = 'http://ecn.dev.virtualearth.net/REST/v1/Locations/' + pin.City + ',' + pin.Country + '?output=json&jsonp=GeocodeCallback&key=' + credentials;
CallRestService(geocodeRequest);
});
function CallRestService(request) {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", request);
document.body.appendChild(script);
}
功能GeocodeCallback(结果){..做的结果回调, - >我要加入一些pin信息在这里}
因为每个sccipt添加到文档(document.body.appendChild(script);)它将运行 - >和回调,你不能添加更多的参数。
我通过AJAX请求解决其(犯规添加到文档的任何更多)中,当AJAX调用成功 - >我所说的GeocodeCallback(结果,销) 下面是完整的代码。
function MakeGeocodeRequest(credentials) {
var pins = checkLocation.d;
$.each(pins, function (index, pin) {
$.ajax({
url:"http://ecn.dev.virtualearth.net/REST/v1/Locations/",
dataType: "jsonp",
data:{key:credentials,q:pin.City + ',' + pin.Country},
jsonp:"jsonp",
success: function(result){
GeocodeCallback(result,pin);
}
});
});
}
function GeocodeCallback(result,pin) { ... to do here}