How to fix error: The message received from the server could not be parsed

前端 未结 10 1594
余生分开走
余生分开走 2020-12-15 21:30

We have a Sharepoint solution that uses AJAX. The button that triggers this is inside an update panel.

One of the things that we do is generate a MS Word document, t

10条回答
  •  攒了一身酷
    2020-12-15 21:47

    I've struggled with this for a few hours. Doing an ajax request within my WebForms Code-Behind file wasn't working & using an UpdatePanel resulted in that annoying error and I wasn't able to find a solution. Finally I found a solution that works!

    • Somewhere in your project create an .ashx (Generic Handler) file. I created mine within a top level services folder so: Services\EventsHandler.ashx. When you do this you should end up with both an .ashx & .ashx.cs file.
    • Inside the ashx.cs file you'll find a ProcessRequest method where you can put all of your code.
    • You can call this method doing something similar to the following in your javascript file:

      $('#MyButton').click(function () {
          var zipCode = $('#FBZipBox').val();
      
          $.getJSON('/Services/EventsHandler.ashx?zip=' + zipCode, function (data) {
              var items = [];
              $.each(data.Results, function (key, item) {
              items.push('item.Date');
          });
      }).complete(function () {
          // More Logic
      });
      return false;});
      
    • Within your ashx.cs file you can access the query parameters using:

      var category = context.Request.QueryString["zipCode"];

    • You can then return the result using:

      context.Response.Write(yourResponseString);

提交回复
热议问题