62,046
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript" src="area.js" charset="GB2312"></script>
<script type="text/javascript" src="search-results.js" charset="GB2312"></script>
<script type="text/javascript" charset="GB2312" src="header.js"></script>
var zone = [{
"zone_id": "15",
"city_id": "12",
"zone_name": "朝阳区"
},
{
"zone_id": "16",
"city_id": "12",
"zone_name": "东城区"
}]
var area = [{
"area_id": "22",
"area_name": "\u4e09\u91cc\u5c6f",
"zone_id": "15",
"area_x": 116.45345,
"area_y": 39.93452
},
{
"area_id": "23",
"area_name": "\u5b89\u8d1e",
"zone_id": "15",
"area_x": 116.40453,
"area_y": 39.96906
}]
var school = [{
"school_id": "4",
"school_name": "\u6e05\u534e\u5927\u5b66",
"zone_id": "17",
"school_x": 116.32608,
"school_y": 40.00161
},
{
"school_id": "5",
"school_name": "\u5317\u4eac\u5927\u5b66",
"zone_id": "17",
"school_x": 116.30605,
"school_y": 39.99314
}]
context.Response.ContentType = "text/javascript";
context.Response.Write(str);
<script type="text/javascript" src="area.ashx" charset="GB2312"></script>
现在无效了?<script type="text/javascript" src="area.aspx" charset="GB2312"></script>
也没有问题。关键就是输出的不能是完整的http流,必须执行response.clear。
voca.Append("{\"voce\":[{\"code\":\"null\"}]}");
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); ;
context.Response.Write(voca.ToString());
context.Response.End();
//城市下拉列表
$("#selPro").change(function() {
var option = "";
$.ajax({
type: "post",
url: "homeHandler/HomeProvince.ashx",
dataType: "json",
data: "proStr=" + $("#selPro").val(),
success: function(message) {
if (message != null) {
$("#selCity option").remove();
option += "<option value=\"0\">==请选择==</option>";
$.each(message.city, function(i, item) {
option += "<option value=\"" + item.id + "\">" + item.name + "</option>";
});
}
$("#selCity").append(option);
}
});
});
public void ProcessRequest(HttpContext context)
{
//得到城市Id
int proId = Convert.ToInt32(context.Request.Params["proStr"]);
if (proId != 0)
{
//根据城市Id查询城市下的区县
List<City> listCity = CityManager.GetAllByProId(proId);
int i = 0;
StringBuilder strJSON = new StringBuilder();
strJSON.Append("{\"city\":[");
foreach (City city in listCity)
{
if (i < (listCity.Count - 1))
{
strJSON.Append("{");
strJSON.Append("\"id\":");
strJSON.Append(Convert.ToInt32(city.CityId));
strJSON.Append(",");
strJSON.Append("\"name\":\"");
strJSON.Append(city.CityName);
strJSON.Append("\"},");
}
if (i == (listCity.Count - 1))
{
strJSON.Append("{");
strJSON.Append("\"id\":");
strJSON.Append(Convert.ToInt32(city.CityId));
strJSON.Append(",");
strJSON.Append("\"name\":\"");
strJSON.Append(city.CityName);
strJSON.Append("\"}");
}
i++;
}
strJSON.Append("]}");
context.Response.Write(strJSON.ToString());
}
}