日期:2014-05-17  浏览次数:20550 次

JS读取数据库数据问题
JScript code


function secRing(){ 
   var secRingCenter = new BMap.Point(118.500272,31.698775);
   map.clearOverlays();         
   var secRing = [
    new BMap.Point(118.502147,31.697776),
    new BMap.Point(118.501842,31.697692),
    new BMap.Point(118.501195,31.697738),
    new BMap.Point(118.499704,31.697968),
    new BMap.Point(118.499165,31.698552),
    new BMap.Point(118.499964,31.699612),
    new BMap.Point(118.500342,31.699604),
    new BMap.Point(118.501078,31.69889),
    new BMap.Point(118.501689,31.698268),
    new BMap.Point(118.501689,31.698268),
   ];
   //创建多边形
    var secRingPolygon = new BMap.Polygon(secRing, {strokeColor: "#ff0000", strokeWeight:2, strokeOpacity:0.5});
    map.addOverlay(secRingPolygon);//添加多边形到地图上
    map.setViewport(secRingPolygon.getPath());    //调整视野  
}



如果我想把坐标数据从数据库读取,应该怎么做呢?后台代码是C#写的,下面的代码为什么一直报错,var Num=<%=Num %>;应为表达式
JScript code

function secRing(){
    var secRingCenter = new BMap.Point(118.5129, 31.675991);
    var Num=<%=Num %>;
    var secRing=[];
   for(var i=0;i<Num/2;i++)
   {
        var temp=new BMap.Point(boundaryDatas[2*i],boundaryDatas[2*i+1]);
        secRing.push(temp);
   }
    var secRingPolygon = new BMap.Polygon(secRing, {strokeColor:"blue", strokeWeight:3, strokeOpacity:0.5});
    map.addOverlay(secRingPolygon);//添加多边形到地图上
    map.setViewport(secRingPolygon.getPath());    //调整视野  
}



------解决方案--------------------
可以通过jquery对应功能读取,可以用类似这样的代码读取
//返回DataSet(XML)
$(document).ready(function() {
$('#btn5').click(function() {
$.ajax({
type: "POST",
url: "WebService1.asmx/GetDataSet",
data: "{}",
dataType: 'xml', //返回的类型为XML ,和前面的Json,不一样了
success: function(result) {
//演示一下捕获
try {
$(result).find("Table1").each(function() {
$('#dictionary').append($(this).find("ID").text() + " " + $(this).find("Value").text());
});
}
catch (e) {
alert(e);
return;
}
},
error: function(result, status) { //如果没有上面的捕获出错会执行这里的回调函数
if (status == 'error') {
alert(status);
}
}
});
});
});
------解决方案--------------------
可以写到 aspheddinFiled中 JS读取VALUE