gpt4 book ai didi

c# - 使用 C# 和 Jquery 的 AJAX 中的汉字问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:51 25 4
gpt4 key购买 nike

我收到带有中文字符的 Ajax 错误,任何人都可以分享解决方法吗?

错误 enter image description here

Jquery

var jqxhr = $.post("Handler1.ashx", function () {
alert("success");
}).fail(function (data) {
alert("error");
});

C#

public void ProcessRequest(HttpContext context)
{
var ticketResponse = new TicketResponse();
ticketResponse.AddedCount = 23;

// All tickets were available and were added to the cart
ticketResponse.Success = true;
ticketResponse.SuccessItems = new List<SuccessfullItem>
{
new SuccessfullItem()
{

OrderItemId = 1,
Title = "【桃姐與我】舞台劇(粵語)粵語)"
}
};


var output = Serializer.Serialize(ticketResponse);
context.Response.AddHeader("Content-Type", "application/json");
context.Response.AddHeader("Content-Length", output.Length.ToString());
context.Response.AddHeader("Content-Disposition", "inline");
context.Response.AddHeader("Content-Transfer-Encoding", "text");
context.Response.Write(output);
context.Response.Flush();
context.ApplicationInstance.CompleteRequest();
}

最佳答案

我找到了解决方案....它不适用于 Generic Handler,但它可以与 webservice 一起正常工作,没有任何问题。

[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public Handler1.TicketResponse HelloWorld()
{
var ticketResponse = new Handler1.TicketResponse();
ticketResponse.AddedCount = 23;

// All tickets were available and were added to the cart
ticketResponse.Success = true;
ticketResponse.SuccessItems = new List<Handler1.SuccessfullItem>
{
new Handler1.SuccessfullItem()
{

OrderItemId = 1,
Title = "【桃姐與我】舞台劇(粵語)粵語)"
}
};

return ticketResponse;
}

关于c# - 使用 C# 和 Jquery 的 AJAX 中的汉字问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18259087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com