我根本需要getJson吗? [英] do I need getJson at all?
问题描述
$(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);
}
}
);
}
);
});
我使用该脚本对页面changemap.cshtml
进行ajax调用,该页面执行以下操作
I use that script to make an ajax call to the page changemap.cshtml
which does the following
@{
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 id=@0";
var row=db.QuerySingle(dbCmd,countryId);
if(null!=row)
{
Json.Write(row,Response.Output);
}
}
}
}
这是将以json格式从数据库中查询的数据返回给客户端.初始化函数定义为
That is to return the queried data from the database in json format to the client. The Initialize function is defined as
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标签时,什么也没有发生.我想我想念更多的脚本来使我的应用程序正常工作.
But when I click the div tag of class viewmap
, nothing happens. I think I miss some more script to get my application to work correctly.
我只尝试实现一个简单的Google地图视图,在该视图中,一旦用户单击一个地名作为超链接,就会重新加载与其匹配的地图.
I only try to implement a simple google map view in which once the user clicks a place name as a hyperlink will reload the map that matches with it.
推荐答案
我认为
var responseURL = "~/changemap?id=" + id;
应该是
var responseURL = '@(Url.Content("~/changemap")+"?id=")' + id;
这篇关于我根本需要getJson吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!