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 />";
});
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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); } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步