系统:win10 pro
环境:VS2015 企业版
额,没有用过ajax,有大神路过,发现了问题,烦请赐教。实在头疼,做一个demo,现在ajax不通,实在想狗带。额,我是小白,代码恶心,大神们忍着恶心看下。
webconfig配置如下:
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
</configuration>
调用页面如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 900px;height:600px; margin:0 auto;border:1px solid #F00"></div>
<div>
<div id="seleted-province" style="width: 100%; height: 800px;">
</div>
</div>
<!-- 引入 echarts.js -->
<script src="scripts/echarts.min.js"></script>
<script src="scripts/china.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
var g_rootpath = getRootPath();
option = {
tooltip: {
trigger: 'item',
formatter: '{b}'
},
toolbox:{
show:true,
orient:'vertical',
x:'right',
y:'center',
feature:{
mark:{show:true},
dataView:{show:true,readOnly:false}
}
},
series: [
{
name: '中国',
type: 'map',
mapType: 'china',
mapLocation:{
x:'left',
y:'top',
width:'80%'
},
roam:true,
selectedMode : 'multiple',
label: {
normal: {
show: true
},
emphasis: {
show: true
}
},
itemStyle:{
emphasis:{label:{show:true}}
},
data:[
{name: '北京', selected:false},
{name: '天津', selected:false},
{name: '上海', selected:false},
{name: '重庆', selected:false},
{name: '河北', selected:false},
{name: '河南', selected:false},
{name: '云南', selected:false},
{name: '辽宁', selected:false},
{name: '黑龙江', selected:false},
{name: '湖南', selected:false},
{name: '安徽', selected:false},
{name: '山东', selected:false},
{name: '新疆', selected:false},
{name: '江苏', selected:false},
{name: '浙江', selected:false},
{name: '江西', selected:false},
{name: '湖北', selected:false},
{name: '广西', selected:false},
{name: '甘肃', selected:false},
{name: '山西', selected:false},
{name: '内蒙古', selected:false},
{name: '陕西', selected:false},
{name: '吉林', selected:false},
{name: '福建', selected:false},
{name: '贵州', selected:false},
{name: '广东', selected:false},
{name: '青海', selected:false},
{name: '西藏', selected:false},
{name: '四川', selected:false},
{name: '宁夏', selected:false},
{name: '海南', selected:false},
{name: '台湾', selected:false},
{name: '香港', selected:false},
{name: '澳门', selected:false}
]
}
],
animation:false
};
myChart.on('click',function(params){
var city=params.name;
getProjectInfos(city);
});
function getRootPath() {
var strFullPath = window.document.location.href;
var strPath = window.document.location.pathname;
var pos = strFullPath.indexOf(strPath);
var prePath = strFullPath.substring(0, pos);
var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
return (prePath + postPath);
}
myChart.setOption(option);
function getProjectInfos(province) {
var url_base = g_rootpath;
alert(url_base);
$.ajax({
type: "GET",
async: false,
url: url_base + "/DataGetService.asmx/HelloWorld",
dataType:"json",
success: function (msg) {
alert(msg.d);
},
error: function (err) {
console.print(err);
//alert("ERROR");
}
});
}
</script>
</body>
</html>
webservice代码:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
public class DataGetService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
我添加webconfig里的post和get节点之后,就不能运行了。就出现了图一所示错误。