При условии, что вы не контролируете вызываемую страницу ...
ResponseText специально предназначен только для чтения (по разным причинам).Конечно, вы можете вставить промежуточную функцию JavaScript в любое из следующих событий: OnSuccess, OnError и OnComplete.Эта функция может изменить ваши данные и реагировать по-разному в зависимости от ваших критериев.
ОБНОВЛЕНИЕ: Как и было обещано, ниже приведен класс контроллера, который я использую для одного из своих приложений.Обратите внимание, что ExceptionManager, содержащийся в области USAGE, содержит копию PeepingTom.Controller.Также обратите внимание, что ExceptionManager передается в контроллер (как контекст) ... и как таковой ... он перехватывает все вызовы.
Конечно, ваши классы могли бы сделать это в разобранном виде.Если вы хотите, чтобы все ваши классы использовали один и тот же контроллер (а не имели свой собственный экземпляр) ... вы, безусловно, могли бы сделать это.Вот копия диспетчера исключений, который использует контроллер (см. Выше)
<script type="text/javascript">
var ExceptionManager = (function($) {
var publicInstances = {};
// ***********************
// Observer
publicInstances.Observer = Observer;
function Observer(userControlId, asOf) {
// ********** PROPERTIES **********
var Self = this;
/// <summary>Controls long-polling communications.</summary>
this.Controller = null;
/// <summary>Represents a utility class-instance.</summary>
this.Utility = null;
/// <summary>Represents the Viewer object.</summary>
this.Viewer = null;
/// <summary>The TEMPLATE ID used in creating an observation.</summary>
this.TemplateId = "#template-exceptionManager-Exception";
/// <summary>Represents a collection of observation objects.</summary>
this.Observations = null;
/// <summary>Used to pause processing of observations.</summary>
this.Pause = false;
/// <summary>Alters the speed with which observations are processed.</summary>
this.PauseInterval = 2000;
/// <summary>Determines how long to wait until the next long-poll is executed.</summary>
this.WaitInterval = 2000;
/// <summary>The design-time Id of this user-control instance.</summary>
this.UserControlId = userControlId;
/// <summary>The datetime stamp used in determining which observations to gather-up.</summary>
this.AsOf = asOf;
/// <summary>The ID of the last observation in the current batch.</summary>
this.LastId = 0;
/// <summary>The relative path of the long-polling processor.</summary>
this.ProcessorUrl = '<%=ResolveUrl("~/Handlers/ActivityExceptionProcessor.ashx")%>';
/// <summary>The relative path of the long-polling controller.</summary>
this.ControllerUrl = '<%=ResolveUrl("~/Handlers/ActivityExceptionController.ashx")%>';
// ********** METHODS **********
/// <!-- Initialization -->
/// <summary>Initializes the Observer.</summary>
this.Initialize = function() {
// Find the activityViewer within the document (the object that manages the display-queue)
if ((activityViewer != null) && (activityViewer.IsInitialized)) {
Self.Controller = new PeepingTom.Controller(Self, Self.ProcessorUrl, Self.ControllerUrl);
Self.Controller.WaitInterval = Self.WaitInterval;
Self.Utility = new PeepingTom.Utility();
Self.Observations = new Array; // THIS objects queue of observations.
Self.Viewer = activityViewer;
Self.InitializeQueue(); // THIS objects queue of observations.
Self.Controller.Fetch();
}
else
setTimeout(Self.Initialize, 2000); // Every 2 seconds
}
/// <!-- Initialization -->
/// <summary>Initializes the queue that processes Observations.</summary>
this.InitializeQueue = function() {
if (!Self.Pause) {
if (Self.Observations.length > 0) {
var observation = Self.Observations.pop();
Self.AppendObservation(observation);
}
setTimeout(Self.InitializeQueue, Self.PauseInterval);
}
}
/// <summary>Enqueue's this observer's newly found Observations.</summary>
this.Enqueue = function(observations) {
if ($(observations).length > 0) {
var lastItem = $(observations).last();
Self.LastId = lastItem[0].Id;
$(observations).each(function() {
// Append dynamic properties
this.TemplateId = Self.TemplateId;
// Append dynamic events
this.OnProcessed = function() { Self.OnProcessed(this); };
Self.Viewer.Enqueue(this);
});
}
}
/// <summary>Returns a populated XMLHttpRequest object.</summary>
this.GetRequestObject = function() {
var request = { UserControlId: Self.UserControlId, AsOf: Self.AsOf };
return request;
}
// ********** EVENTS **********
/// <!-- Notification -->
/// <summary>Notifies this control when an observation is processed.</summary>
this.OnProcessed = function(observation) {
if (observation.Id == Self.LastId) {
Self.Controller.TimerHandle = setTimeout(function() { Self.Controller.Fetch(); }, Self.WaitInterval);
}
}
/// <!-- Communication -->
/// <summary>A function called when the request finishes.</summary>
/// <see cref="http://api.jquery.com/jQuery.ajax/"></see>
/// <param name="xmlHttpRequest">The XMLHttpRequest object.</param>
/// <param name="status">A string containing the success or error code.</param>
this.OnComplete = function(xmlHttpRequest, status) {
}
/// <!-- Communication -->
/// <summary>Setup default values for ALL ajax requests</summary>
/// <see cref="http://api.jquery.com/jQuery.ajax/"></see>
/// <param name="xmlHttpRequest">The XMLHttpRequest itself (object).</param>
/// <param name="status">A string describing the type of error that occurred</param>
/// <param name="error">The exception object (optional).</param>
this.OnError = function(xmlHttpRequest, status, error) {
Self.Controller.Log("ExceptionManager - OnError: " + error);
alert("ExceptionManager - OnError");
}
/// <!-- Communication -->
/// <summary>(optional) Actions to take when the session becomes invalid.</summary>
/// <see>OnSuccess: data.SessionValid = false</see>
this.OnSessionExpired = function(data) {
Self.Controller.Log("ExceptionManager - OnSessionExpired");
alert("ExceptionManager - OnSessionExpired");
}
/// <!-- Communication -->
/// <summary>A function to be called if the request succeeds.</summary>
/// <see cref="http://api.jquery.com/jQuery.ajax/"></see>
/// <param name="data">The data returned from the server (formatted according to the 'dataType' parameter).</param>
/// <param name="status">A string describing the status.</param>
/// <param name="xmlHttpRequest">The XMLHttpRequest object (available as of jQuery 1.4).</param>
this.OnSuccess = function(data, status, xmlHttpRequest) {
Self.AsOf = data.AsOf;
if (data.Observations) {
if (data.Observations.length > 0)
Self.Enqueue(data.Observations);
else
Self.Controller.TimerHandle = setTimeout(function() { Self.Controller.Fetch(); }, Self.WaitInterval);
}
}
}
return publicInstances;
})(jQuery);
</script>