gpt4 book ai didi

jquery - 即使 OnResultExecuted 成功调用后,JsonResult 也未返回

转载 作者:行者123 更新时间:2023-12-01 06:02:58 26 4
gpt4 key购买 nike

我有一个“无 session ” Controller ,其操作返回 JsonResult。我的客户端 Javascript 使用 Jquery ajax 通过 HTTP GET 调用此操作

[HttpGet]
public JsonResult Index()
{
....
// myResult has three properties of type bool, int and a string

var jsonResult = Json(myResult, "application/json", JsonRequestBehavior.AllowGet);
return jsonResult;
}

该代码被执行,并且我已经验证了 OnResultExecuted 被调用,没有任何异常。

客户端JS

xhrNotification = $.ajax({
url: '/MyController/', // default action
type: 'get',
dataType: 'json',
cache: false,
async: true,
success: function (n, timeout, message) {

},
error: function (data) {

}
});

但是 jsonResult 只是偶尔到达客户端。我一直在使用 Fiddler 观察请求/响应。即使执行了我的操作,HTTP 请求也没有响应。我正在 Visual Studio 2010 下开发这个。

感谢任何帮助。

编辑:在进一步调试时,我发现执行操作后引发了异常

System.Net.Sockets.SocketException occurred
Message=An established connection was aborted by the software in your host machine
Source=System
ErrorCode=10053
NativeErrorCode=10053
StackTrace:
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)

部分堆栈跟踪如下

System.dll!System.Net.Sockets.Socket.Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x5a bytes 
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Connection.WriteBody(byte[] data, int offset, int length) + 0x40 bytes
[Appdomain Transition]
> WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.FlushResponse(bool finalFlush) + 0x128 bytes
System.Web.dll!System.Web.HttpResponse.Flush(bool finalFlush) + 0x4cb bytes
System.Web.dll!System.Web.HttpRuntime.FinishRequest(System.Web.HttpWorkerRequest wr, System.Web.HttpContext context, System.Exception e) + 0x80 bytes
System.Web.dll!System.Web.HttpRuntime.OnHandlerCompletion(System.IAsyncResult ar) + 0xa6 bytes
System.Web.dll!System.Web.HttpAsyncResult.Complete(bool synchronous, object result, System.Exception error, System.Web.RequestNotificationStatus status) + 0x3e bytes
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x25e bytes
System.Web.dll!System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(System.Exception error) + 0x28 bytes
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(System.IAsyncResult ar) + 0x183 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncUtil.WrapCallbackForSynchronizedExecution.AnonymousMethod__1() + 0x14 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync.AnonymousMethod__3() + 0x16 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync<System.Web.Mvc.Async.AsyncVoid>.AnonymousMethod__0(object o) + 0x32 bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback callback, object state) + 0x4a bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.CallCallback(System.Threading.SendOrPostCallback callback, object state) + 0x5f bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.Send(System.Threading.SendOrPostCallback callback, object state) + 0x9 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync<System.Web.Mvc.Async.AsyncVoid>(System.Threading.SynchronizationContext syncContext, System.Func<System.Web.Mvc.Async.AsyncVoid> func) + 0x58 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync(System.Threading.SynchronizationContext syncContext, System.Action action) + 0x46 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncUtil.WrapCallbackForSynchronizedExecution.AnonymousMethod__0(System.IAsyncResult asyncResult) + 0x6f bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<bool>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<bool>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes

最佳答案

尝试使用此调用,看看会发生什么:(可能需要确保将类型设置为“GET”,而不是“get”)

$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: '/MyController/',
success: function (data) {

},
error: function(e) {
},
complete: function () {

}
});

此外,您可能只想在 Controller 中执行此操作:

return Json(myResult, JsonRequestBehavior.AllowGet);

关于jquery - 即使 OnResultExecuted 成功调用后,JsonResult 也未返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9413923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com