Мне нужно указать переменную, которая у меня есть в строке запроса, чтобы указать, какие push-штыри рисовать на моей карте. В настоящее время мне приходится жестко записывать имя пива, как я сделал с "Stella" в заявлении if. Есть ли способ, которым я могу ссылаться на мою строку запроса (beerName = Stella), чтобы изменить это вместо этого. Это все на главной странице. Любая помощь приветствуется.
$(document).ready(function () {
$.ajax({
url: "Handler2.ashx",
type: "post",
data: { "Action": "SearchByLocation" },
success: function (data) {
for (var i = 0; data.Locations.length - 1; i++) {
var pushPin2 = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(data.Locations[i].Latitude, data.Locations[i].Longitude), null);
$("#newdiv li").append("<li><a href='" + "Main.aspx?beerName=" + data.Locations[i].beerName + "'>" + data.Locations[i].beerName + "</a></li>")
collectionInMemory = data;
if (data.Locations[i].beerName == "Stella") {
map.entities.push(pushPin2);
}
}
for (var j = 0; j < collectionInMemory.Locations.length - 1; j++) {
if(collectionInMemory.Locations[j].BeerName = "Stella") alert("datada");
}
},
error: function () {
alert("failure");
$("#result").html('There is error while submit');
}
});
Вы можете использовать встроенный фрагмент ASP.NET таким образом, и он будет отображать переменную строки запроса
if (data.Locations[i].beerName == <%= Request.QueryString("beerName") %>) {
map.entities.push(pushPin2);
}