Ajax请求parsererror来自服务器 [英] Ajax request parsererror comes from server

查看:85
本文介绍了Ajax请求parsererror来自服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行我的休息api之后,我收到一个textstatus'parsererror'的错误回复。(有时只显示parsererror)



我使用的是iframe在窗口中并从那里模仿ajax请求。(IE显示解析器错误,但chrome工作正常)。



请参阅我的以下请求。





After executing my rest api I am getting call back to error with a textstatus 'parsererror'.(Sometimes only it shows parsererror)

I am using an iframe in window and imitate the ajax request from there.(IE shows the parser error but chrome works fine).

please see my below request.


return $.ajax({
               type: 'GET',
               async: true,
               contentType: 'application/json; charset=utf-8',
               url: this.serviceUrl + 'Documents?contextType=' + this.currentContextType + "&contextUid=" + this.currentContextUuid + "&dataSource=" + this.currentContextDataSource,
               error: (jqXHR, textStatus, errorThrown) => {
                   if (jqXHR.status == 502 || !navigator.onLine) {
                       Common.Utils.connectionLost();
                   }
                   else if (textStatus === "parsererror") {
                       try {
                           throw new Error('textStatus:parsererror');
                       }
                       catch (e) {
                           console.log(e);
                       }
                   }
                   else if (jqXHR.status == 500 && jqXHR.responseText) {
                       WorkflowUI.Handlers.ErrorHandler.HandleErrorServiceLevel(JSON.parse(jqXHR.responseText));
                   }
               },
               success: (response) => {
                   this.tableData = response;
                   this.populateTable();
                   if (this.currentWidgetPosition.toLocaleLowerCase() === "left") {
                       setTimeout(function () {
                           parent.WorkflowUI.PowerJacketSingleton.showScannerWidget(this.currentContextUuid, this.currentContextDataSource);
                       }, 0);
                   }
               }
           });





我的尝试:



i已经尝试过POST并尝试通过捕获异常错误来避免jquery对象不支持错误





任何方式在没有显示jquery错误的情况下抑制此错误。



任何答案都表示赞赏。



What I have tried:

i have tried by POST and tried by catch the exception in error to avoid jquery object not supported error


Any way to suppress this error without showing jquery error.

Any answer is appreciated.

推荐答案

.ajax( {
类型:'GET',
async:true,
contentType:'application / json; charset = utf-8',
url:this.serviceUrl +'Documents? contextType ='+ this.currentContextType +& contextUid =+ this.currentContextUuid +& dataSource =+ this.currentContextDataSource,
error:(jqXHR,textStatus,errorThrown)=> {
if(jqXHR.status == 502 ||!navigator.onLine){
Common.Utils.connectionLost();
}
else if(textS tatus ===parsererror){
try {
throw new Error('textStatus:parsererror');
}
catch(e){
console.log(e);
}
}
else if(jqXHR.status == 500&& jqXHR.responseText){
WorkflowUI.Handlers.ErrorHandler.HandleErrorServiceLevel(JSON.parse(jqXHR。 responseText的));
}
},
成功:(响应)=> {
this.tableData = response;
this.populateTable();
if(this.currentWidgetPosition.toLocaleLowerCase()===left){
setTimeout(function(){
parent.WorkflowUI.PowerJacketSingleton.showScannerWidget(this.currentContextUuid,this.currentContextDataSource );
},0);
}
}
});
.ajax({ type: 'GET', async: true, contentType: 'application/json; charset=utf-8', url: this.serviceUrl + 'Documents?contextType=' + this.currentContextType + "&contextUid=" + this.currentContextUuid + "&dataSource=" + this.currentContextDataSource, error: (jqXHR, textStatus, errorThrown) => { if (jqXHR.status == 502 || !navigator.onLine) { Common.Utils.connectionLost(); } else if (textStatus === "parsererror") { try { throw new Error('textStatus:parsererror'); } catch (e) { console.log(e); } } else if (jqXHR.status == 500 && jqXHR.responseText) { WorkflowUI.Handlers.ErrorHandler.HandleErrorServiceLevel(JSON.parse(jqXHR.responseText)); } }, success: (response) => { this.tableData = response; this.populateTable(); if (this.currentWidgetPosition.toLocaleLowerCase() === "left") { setTimeout(function () { parent.WorkflowUI.PowerJacketSingleton.showScannerWidget(this.currentContextUuid, this.currentContextDataSource); }, 0); } } });





我的尝试:



i已经尝试过POST并尝试通过捕获异常错误来避免jquery对象不支持错误





任何方式在不显示jquery错误的情况下抑制此错误。



任何答案都表示赞赏。



What I have tried:

i have tried by POST and tried by catch the exception in error to avoid jquery object not supported error


Any way to suppress this error without showing jquery error.

Any answer is appreciated.


这篇关于Ajax请求parsererror来自服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆