2

我收到带有汉字的 Ajax 错误,任何人都可以分享修复吗?

错误 在此处输入图像描述

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();
        }
4

1 回答 1

0

我找到了解决方案....它不能与通用处理程序一起使用,但它可以与 web 服务一起正常工作,没有任何问题。

[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;
    }
于 2013-08-31T00:04:11.180 回答