dhl:ajax无法跨域改用getJSON(解决服务器返回json数据中文为乱码的问题$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; chars)

//ajax无法跨域改用getJSON
    var url = "<%=webcode.PublicMethod.url.HttpAndPoint%>/call/ChatSubmitJson?callback=?";
    var data = { wrEditor: encodeURI(showdData,"utf-8"), id: "<%=ViewData["id"]%>" };
     $.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});
$.getJSON(url, data, function(backdata) {
//alert(backdata.wrEditor);
parent.olEditor.document.charset="utf-8";
parent.olEditor.document.body.innerHTML ="<span style='color:red;font-size:13px;'>"+backdata.wrEditor+"</span><br />";
});

 

 

 public ContentResult ChatSubmitJson()
        {
            int enterpriseId = Convert.ToInt32(Request["id"] ?? "0");
            var enterprise = _enter.GetEnterprise(enterpriseId);
            string callback = Request.QueryString.Get("callback");
            string question = HttpUtility.UrlDecode(Request["wrEditor"], Encoding.UTF8);
            string content = string.Empty;
            string shootKeywords = string.Empty;
            string voiceUrl = string.Empty;
            ViewData["Name"] = _enter.GetEnterprise(enterpriseId).FullCompanyName;
            var list = new List<MessageModel>();//messageModel
            list.Add(new MessageModel
                         {
                             ClientId = _guid + enterpriseId,
                             Speaker = "我",
                             EnterpriseId = enterpriseId,
                             Content = question,
                             CreateTime = DateTime.Now,
                             Extend = "问"
            });
            List<AnswerModel> answerList = _manager.GetAnswer(question, enterpriseId, _guid + "&" + enterpriseId, ref shootKeywords, ref voiceUrl);
            foreach (AnswerModel model in answerList)//把企业回答写入到MessageModel
            {
                list.Add(_manager.NewSendMessage(string.Format("{0}智能前台", enterprise.ShortCompanyName), model.Answer, _guid + "&" + enterpriseId));
            }
            foreach (MessageModel message in list)//组合前台显示内容
            {
                string color = (message.Extend == "问") ? "#000" : "blue";
                content += string.Format("<font color=\"" + color + "\">{0}  {1}<br />{2}</font><br /><br />", message.Speaker, message.CreateTime.ToString("HH:mm:ss"), message.Content);
            }
            var vUrl = string.Format("{0}{1}", ConfigFile.VoiceFileUrl, voiceUrl);
            string backjsondata = "({'id':'" + enterpriseId + "','wrEditor':'" + content + "','vid':'" + vUrl + "'})";
            string mybackdata = callback + backjsondata;
            return Content(mybackdata);
        }
posted @ 2010-06-24 10:38  肚肚  阅读(946)  评论(0编辑  收藏  举报