使用C#和AJAX的AJAX中的汉字问题jQuery的

时间:2013-08-15 18:19:21

标签: c# jquery asp.net

我收到中文字符的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();
        }

1 个答案:

答案 0 :(得分:0)

我找到了解决方案....它不能与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;
    }