dragy
dragy

Reputation: 187

asp.net web forms with ajax call returning ienumerable

I work with asp.net web form and want insert pushpins on bing map. I use jquery ajax call to obtain list of photos where i keep longitude and latitude among the others properties.

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:

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?

Upvotes: 0

Views: 319

Answers (1)

Shah
Shah

Reputation: 1399

Response is available from response.d so change

$.each(response, function (index, photo) {

To

$.each(response.d, function (index, photo) {

Upvotes: 2

Related Questions