[英]asp.net web forms with ajax call returning ienumerable
I work with asp.net web form and want insert pushpins on bing map. 我使用asp.net网络表单,并希望在bing地图上插入图钉。 I use jquery ajax call to obtain list of photos where i keep longitude and latitude among the others properties.
我使用jquery ajax调用来获取照片列表,在这些列表中我在其他属性中保持经度和纬度。
HTML: HTML:
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
<div style="width: 100px;">
<div style="float: left; width: 700px">
<asp:Panel ID="pnlMap" runat="server" Style="position: absolute; width: 600px; height: 450px;" />
</div>
</div>
Web Method: 网络方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
public static IEnumerable<Photo> GetAllVisiblePhotos()
{
using (SqlConnection conn = new SqlConnection( ... return photos;
and it realy returns list of photos. 它确实返回照片列表。
JavaScript functions are: JavaScript函数是:
function GetPhotos() {
$.support.cors = true;
try {
$.ajax({
url: 'Default.aspx/GetAllVisiblePhotos',
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: DisplayPics,
error: OnError
});
}
catch (err) {
alert(err.message);
}
}
function DisplayPics(response) {
var location;
var pin;
$.each(response, function (index, photo) {
location = new Microsoft.Maps.Location(photo.Latitude, photo.Longitude);
pin = new Microsoft.Maps.Pushpin(location);
pin.Title = photo.Title;
pin.ID = photo.PhotoID;
dataLayer.push(pin);
});
}
But I don't get any pushpin on the map. 但是我在地图上没有任何图钉。 What is wrong?
怎么了?
Response is available from response.d so change 可以从response.d获得响应,因此请进行更改
$.each(response, function (index, photo) {
To 至
$.each(response.d, function (index, photo) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.