views:

467

answers:

2

I send request from asp.net page and then wait for response, calling GetCommand via SetInterval method:

    function GetCommand(id, sid) {
 getCommandResponse = $.ajax({
  type: "POST",
  async: true,
  url: "../WebServices/TSMConsole.asmx/GetCommand",
  data: "{'param' : '" + id + "', 'sid' : '" + sid + "'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(result, status) {
   AjaxFinishedGet(result, status);
   getCommandResponse = null;
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
            AjaxFailedGet(XMLHttpRequest, textStatus, errorThrown);
   getCommandResponse = null;
  }
 });
}

In AjaxFinishedGet(result, status) I try to extract my data:

    function AjaxFinishedGet(xml, status) {
 endDate = new Date();
 if (xml.d.IsPending == 'false' || endDate - startDate > timeoutMSec) {
  if (getCommand != null) {
   window.clearInterval(getCommand);
   getCommand = null;
   WriteGetCommand(xml.d.Text);
   $("#showajax").fadeOut("fast");
  }
 }
}

However, if Text size is more than 102330 bytes - instead of AjaxFinishedGet, AjaxFailedGet is called :(

I have not found any info neither about some limitation of ajax response data size nor about javascript variable size, at least such variable can hold 1MB without problems. Actually Text may contain 1MB of data...

Where is the problem?

A: 

Well, multiple requests can cause error, perhaps a good solution is to verify that there is no active current request.

var loading = false;
function GetCommand(id, sid) {
    if (loading) {return false;}
    loading =  true;
        getCommandResponse = $.ajax({
         ....
         ....
        });

}

function AjaxFinishedGet(xml, status) {
    loading = false;
    ...
    ...
}
zazk
A: 

James Black, i have no any info about the error:

function AjaxFailedGet(XMLHttpRequest, textStatus, errorThrown) {
 $("#<%= tbResponse.ClientID %>").text(errorThrown);
 if (getCommand != null) {
  window.clearInterval(getCommand);
  $("#showajax").fadeOut("fast");
 }
}
  • errorThrown is empty.

WebServer is IIS7 on Vista x32

zazk, thanks, putting such check is a good point and i will use this flag for reliability. However, in the given case, i don't think it could be the reason of the problem: response output does work always, when data size is 102330 and doesn't work starting from 102331 (i am using new String('x', 102330), so it cannot be any special character problem or something like that).

Alexander