У меня есть следующий код:
$.ajax(
{
url: rootPath + "Framework/GetPartial",
data: { partialName: partialName },
type: "POST",
success: function (response)
{
$('#loading').hide();
$('#partialContent').hide().html(response).fadeIn();
},
error: function (xhr, textStatus, errorThrown)
{
$('#loading').hide();
$('#partialContent').hide().html('An error occurred. Details below:<br /><br />' + xhr.responseText).fadeIn();
}
});
Меня интересует функция обработки ошибок. При возникновении ошибки на сервере в качестве ответа отправляется HTML-страница, содержащая подробную информацию об отладке. Я хотел бы загрузить этот html-ответ на существующую страницу, но включение тегов <HTML>
, <HEAD>
и <BODY>
в ответ нарушает форматирование всей страницы. Как бы я проанализировал только содержимое тега body, используя JQuery в следующем ответе HTML?
<code><html>
<head>
<title>The method or operation is not implemented.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/AlexAndNikki' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The method or operation is not implemented.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br><br>
<b> Exception Details: </b>System.NotImplementedException: The method or operation is not implemented.<br><br>
<b>Source Error:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
Line 19: public PartialViewResult GetPartial(string partialName)
Line 20: {
<font color=red>Line 21: throw new NotImplementedException();
</font>Line 22: //System.Threading.Thread.Sleep(3000);
Line 23: if (!ViewExists(partialName))
Исходный файл: C: \ Users \ alex.ford \ Documents \ Visual Studio 2010 \ Projects \ AlexAndNikki \ AlexAndNikki \ Controllers \ FrameworkController.cs
& nbsp; & nbsp; Линия: 21
Трассировка стека:
[NotImplementedException: The method or operation is not implemented.]
AlexAndNikki.Controllers.FrameworkController.GetPartial(String partialName) in C:\Users\alex.ford\Documents\Visual Studio 2010\Projects\AlexAndNikki\AlexAndNikki\Controllers\FrameworkController.cs:21
lambda_method(Closure , ControllerBase , Object[] ) +127
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +258
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +125
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709
System.Web.Mvc.Controller.ExecuteCore() +162
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
|
Информация о версии: Microsoft .NET Framework Версия: 4.0.30319; ASP.NET версия: 4.0.30319.1
<! -
[NotImplementedException]: метод или операция не реализованы.
в AlexAndNikki.Controllers.FrameworkController.GetPartial (String частичное имя) в C: \ Users \ alex.ford \ Documents \ Visual Studio 2010 \ Projects \ AlexAndNikki \ AlexAndNikki \ Controllers \ FrameworkController.cs: строка 21
at lambda_method (Closure, ControllerBase, Object [])
в System.Web.Mvc.ReflectedActionDescriptor.Execute (ControllerContext controllerContext, IDictionary`2 параметры)
в System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (ControllerContext controllerContext, ActionDescriptor actionDescriptor, параметры IDictionary`2)
в System.Web.Mvc.ControllerActionInvoker. <> c__DisplayClassd. b__a ()
в System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (фильтр IActionFilter, ActionExecutingContext preContext, продолжение Func`1)
в System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters (ControllerContext controllerContext, фильтры IList`1, ActionDescriptor actionDescriptor, параметры IDictionary`2)
в System.Web.Mvc.ControllerActionInvoker.InvokeAction (ControllerContext controllerContext, String actionName)
в System.Web.Mvc.Controller.ExecuteCore ()
в System.Web.Mvc.MvcHandler. <> c__DisplayClass8. b__4 ()
в System.Web.Mvc.Async.AsyncResultWrapper. <> c__DisplayClass1. b__0 ()
в System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute ()
в System.Web.HttpApplication.ExecuteStep (шаг IExecutionStep, логический и завершен синхронно)
->
EDIT:
Есть ли способ загрузить строку ответа в iframe? Это было бы замечательно, если бы это было возможно.
Что-то вроде:
$('#partialContent').html('<iframe>' + xhr.responseText + '</iframe>');
Очевидно, я пробовал этот код, и он не работал, но, может быть, кто-то знает, как заставить iframe решить проблему?