$(document).ready(function()
{
$(".viewmap").click(function()
{
var id = $(this).attr("id");
var responseURL = "~/changemap?id=" + id;
//alert(responseURL);
$.ajax(
{
url: responseURL,
dataType: "json",
type:"GET",
success: function (dt)
{
initialize(dt.Latt, dt.Longt);
}
}
);
}
);
});
我使用腳本來使一個AJAX調用頁面changemap.cshtml
其執行以下操作我需要getJson嗎?
@{
if(!IsPost)
{
if(!Request.QueryString["id"].IsEmpty()&&Request.QueryString["id"].IsInt())
{
var countryId=Request.QueryString["id"];
var db=Database.Open("GoogleMapView");
var dbCmd="SELECT * FROM places WHERE [email protected]";
var row=db.QuerySingle(dbCmd,countryId);
if(null!=row)
{
Json.Write(row,Response.Output);
}
}
}
}
也就是從數據庫中以JSON格式返回查詢的數據到客戶端。初始化函數定義爲
function initialize(lat,lng)
{
var mapOptions = {
center: new google.maps.LatLng(lat,lng),zoom: 8,mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("gmap"),mapOptions);
}
但是當我點擊viewmap
類的div標籤,沒有任何反應。我想我錯過了一些腳本讓我的應用程序正常工作。
我只嘗試實現一個簡單的谷歌地圖視圖,其中一旦用戶點擊地名作爲超級鏈接將重新加載與之匹配的地圖。
成功函數中'dt'的值是多少? –
dt包含從數據庫表中讀取的json格式的數據 –