前台页面
<!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
服务器返回结果
城市:娌堥槼,时间:2013-12-27 11:00:46
在服务器上传入任何值返回结果都是一样的
请大神指教
------解决方案--------------------
显然乱码了嘛。检查服务端的RequestEncoding 和 ResponseEncoding。
客户端和服务端统一成 utf-8
------解决方案--------------------
统一编码格式
------解决方案--------------------
统一编码格式
------解决方案--------------------
客户端和服务端格式不统一,将其统一成 utf-8
------解决方案--------------------