【发布时间】:2013-12-02 21:16:25
【问题描述】:
我在任何地方使用邮政编码查找服务,下面的代码允许我在控制台记录值,但不将其作为对象返回
function StoreFinder_Interactive_RetrieveNearest_v1_10(Key, Origin, MaximumItems, MaximumRadius, MaximumTime, DistanceType, LocationLists) {
$.getJSON("http://services.postcodeanywhere.co.uk/StoreFinder/Interactive/RetrieveNearest/v1.10/json3.ws?callback=?",
{
Key: Key,
Origin: Origin,
MaximumItems: MaximumItems,
MaximumRadius: MaximumRadius,
MaximumTime: MaximumTime,
DistanceType: DistanceType,
LocationLists: LocationLists
},
function (data) {
// Test for an error
if (data.Items.length == 1 && typeof(data.Items[0].Error) != "undefined") {
// Show the error message
alert(data.Items[0].Description);
}
else {
// Check if there were any items found
if (data.Items.length == 0)
alert("Sorry, there were no results");
else {
// PUT YOUR CODE HERE
//FYI: The output is a JS object (e.g. data.Items[0].YourId), the keys being:
distance = data.Items[0].Distance;
console.log(distance);
// name = data.Items[0].Name;
//YourId
//Name
//Description
//Distance
//Time
//Easting
//Northing
//Latitude
//Longitude
return distance;
}
}
});
}
所以我的电话
var data = StoreFinder_Interactive_RetrieveNearest_v1_10("xxxxxxxxxxxxx", $('#postcode').val() );
console.log("data is"+data)
给出未定义的数据。
【问题讨论】: