我理解这个问题。 我收到了<代码>的答复。 内容-类型:文本/html与下文一样。
<textarea>{"ContentEncoding":null,"ContentType":null,"Data":{"prop1":1},"JsonRequestBehavior":1,"MaxJsonLength":null,"RecursionLimit":null}</textarea>
阅读答复的客户法。
function (xhr)
{
try{
console.log(xhr.responseText);
var originalData = $(xhr.responseText);
var jsonResponse = $.parseJSON(originalData.html());
var propValResult = jsonResponse.Data.prop1;
}
catch (e)
{
};
}
下面是服务器边代码,其中我提出了总结性反应。
ASP.NET MVC Customs Result
public class JsonTextWrappedResult : JsonResult
{
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if ((JsonRequestBehavior == JsonRequestBehavior.DenyGet)
&& string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException("Get Not Allowed");
}
var response = context.HttpContext.Response;
response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json";
if (ContentEncoding != null)
{
response.ContentEncoding = ContentEncoding;
}
if (Data != null)
{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string results = "<textarea>" + serializer.Serialize(Data) + "</textarea>";
response.Write(results);
}
}
}
主计长办公室
public JsonTextWrappedResult PracticeInfoFormUpload(HttpPostedFileBase myfile, FormCollection formCollection)
{
var data = this.Json(
new
{
prop1 = 1
});
var result = new JsonTextWrappedResult { Data = data, ContentType = "text/html" };
return result;
}