前台页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://shdesign.soufun.com/js/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var S_Fj=jQuery.noConflict();
S_Fj(document).ready(function() {
// var clientUrl = "http://localhost:4508/WebService.asmx/HelloWorld?jsoncallback=?";
var clientUrl = "http://shdesign.soufun.com/huyong/m/WebService/WebService1.asmx/HelloWorld?jsoncallback=?";
var currentCity = "哈尔滨";
S_Fj.getJSON(
clientUrl,
{ city: currentCity },
function (json) {
S_Fj("#data").html("城市:" +json.city + ",时间:" + json.dateTime);
}
);
});
function OnSuccess(responseData) {
S_Fj("#data").html(responseData.city);
}
function OnError(XMLHttpRequest, textStatus, errorThrown) {
targetDiv = S_Fj("#data");
if (errorThrown || textStatus == "error" || textStatus == "parsererror" || textStatus == "notmodified") {
targetDiv.replaceWith("请求数据时发生错误!");
return;
}
if (textStatus == "timeout") {
targetDiv.replaceWith("请求数据超时!");
return;
}
}
</script>
</head>
<body>
<div id="data"></div>
</body>
</html>
访问wbservices端代码
public void HelloWorld(string city)
{
string callbackMethodName = HttpContext.Current.Request.Params ?? "";
city = string.IsNullOrEmpty(city) ? "北京" : "沈阳";
string result = callbackMethodName + "({\"city\":" + "\"" + HttpUtility.UrlDecode(city) + "\", \"dateTime\":" + "\"" + DateTime.Now + "\"});";
HttpContext.Current.Response.Write(result);
HttpContext.Current.Response.End();
}
本机上返回结果
城市:沈阳,时间:2013-12-27 11:00:46
服务器返回结果
({"city":"娌堥槼", "dateTime":"2013-12-27 11:03:04"});
请大神指教
------解决方案--------------------
HttpUtility.UrlDecode(city,Encoding.GetEncode(gb2312))
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
------解决方案--------------------
http://www.2cto.com/kf/201211/167268.html
------解决方案--------------------