本文介绍了服务器错误总是从MVC HttpPost调用ajax成功回调jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这是我的javascript代码,我的控制器看起来像这样 但是每当出现错误或异常时总是会成功回调我在这里缺少什么 var options = { iframe: true ,类型:' post', url: api / Registration / Register, data:{ data:jsonData}, dataType:' json',成功: function (responseText,statusText,xhr,$ form) { if (statusText == ' success '){} 其他 { // code =='FAIL' } },错误: function (响应,状态,错误){ }}; $(' #registration')。ajaxSubmit(options); [HttpPost] public 任务< HttpResponseMessage>注册() { // 创建任务对象并读取服务器数据 尝试 { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert。 SerializeObject(assistedRegResponse.Response))}; 返回响应; } catch (Exception ex){ throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError,ex));} return task; } 解决方案 表格) { if (statusText == ' success'){} else { // code =='FAIL' } },错误:功能(响应,状态,错误){}}; (' #registration')。ajaxSubmit(options) ; [HttpPost] public 任务< HttpResponseMessage>注册() { // 创建任务对象并读取服务器数据 尝试 { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert。 SerializeObject(assistedRegResponse.Response))}; 返回响应; } catch (Exception ex){ throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError,ex));} return task; } 如果它将成功功能意味着服务器端代码正在成功执行(往返完成没有错误)。如果有任何语法错误,可以在错误函数中捕获。 在你的情况下,如果它正在执行成功方法,则表示一切正常。 This is my javascript code and my controller looks like thisbut whenever there is an error or Exception it always goes to success callback What am i missing herevar options = { iframe: true, type: 'post', url: "api/Registration/Register", data: { "data": jsonData }, dataType: 'json', success: function (responseText, statusText, xhr, $form) { if (statusText == 'success') { } else { //code == 'FAIL' } }, error: function (response, status, err) { }}; $('#registration').ajaxSubmit(options);[HttpPost]public Task<HttpResponseMessage> Register(){ //create task object and read server data try { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(assistedRegResponse.Response)) }; return response; } catch (Exception ex){ throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));} return task;} 解决方案 form) { if (statusText == 'success') { } else { //code == 'FAIL' } }, error: function (response, status, err) { }};('#registration').ajaxSubmit(options);[HttpPost]public Task<HttpResponseMessage> Register(){ //create task object and read server data try { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(assistedRegResponse.Response)) }; return response; } catch (Exception ex){ throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));} return task;}Hi,If it is going to Success function means the server side code is executing successfully(Round trip is completed with no errors). If there are any syntax errors those can be catched in the error function.In your case if it is executing the success method, it means everything is fine. 这篇关于服务器错误总是从MVC HttpPost调用ajax成功回调jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 05:18
查看更多