$.ajax 非ie内核浏览器 兼容问题
$.ajax({
type: "POST", //访问WebService使用Post方式请求
contentType: "application/json", //WebService 会返回Json类型
url: "../WebService1.asmx/PostPage2", //调用WebService的地址和方法名称组合---WsURL/方法名
data: "{url:'http://111.1.37.187:18080/ihometownweb/hometownforum',postData:'busicode=70000&cityname=" + c1 + "'}", //这里是要传递的参数,格式为 data: "{paraName:paraValue}",下面将会看到
dataType: 'json',
success: function(result) { //回调函数,result,返回值
// alert(result.d["content"]);
if (result.d["content"] != "") {
$("#bb").html(result.d["content"] + "</br>");
}
else { alert("请输入省级城市名称"); }
}
});
public CityContent PostPage2(string url, string postData)
{
string err = null;
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
string content = null;
// Encoding encoding = Encoding.UTF8;
Encoding encoding = Encoding.GetEncoding("utf-8");
byte[] data = encoding.GetBytes(postData);
int iConnect = 0;
while (iConnect < 10) //提交10次,如果不成功则返回null
{
// 准备请求...
try
{
// 设置参数
request = (HttpWebRequest)WebRequest.Create(url);
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data, 0, data.Length);
outstream.Close();
//发送请求并获取相应回应数据
response = (HttpWebResponse)request.GetResponse();
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
content = sr.ReadToEnd();
err = string.Empty;
DataContractJsonSerializer _Json3 = new DataContractJsonSerializer(citycontent.GetType());
byte[] _Using3 = System.Text.Encoding.UTF8.GetBytes(content);
System.IO.MemoryStream _MemoryStream3 = new System.IO.MemoryStream(_Using3);
_MemoryStream3.Position = 0;
citycontent = (CityContent)_Json3.ReadObject(_MemoryStream3);
return citycontent;
}
catc