getJson 访问WebServices在服务器上访问值是乱码,在本机上返回确实OK的,求大神指教 [问题点数:100分]

火影-信念 2013-12-27 11:09:31
前台页面

<!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

在服务器上传入任何值返回结果都是一样的



请大神指教
...全文
396 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
本拉灯 2014-01-23
  • 打赏
  • 举报
回复
<!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=utf-8" /> <<===这里UTF-8 <script src="http://shdesign.soufun.com/js/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript" language="javascript">
风一样的大叔 2014-01-23
  • 打赏
  • 举报
回复
客户端和服务端格式不统一,将其统一成 utf-8
  • 打赏
  • 举报
回复
统一编码格式
  • 打赏
  • 举报
回复
统一编码格式
机器人 2014-01-06
  • 打赏
  • 举报
回复
显然乱码了嘛。检查服务端的RequestEncoding 和 ResponseEncoding。 客户端和服务端统一成 utf-8

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧