weixin_33738555 2018-04-09 15:09 采纳率: 0%
浏览 28

Ajax收到错误消息

I have ajax method. I send a request. if a error is recieved, its caught by error: function(data) {

How do i obtain the error message received? front my google chrome,network i can see message received as:

how do i extract the 'message element?

From the back end , i throw error messages like

throw new Exception("There is already a user registered with the email provided");

In chrome i see:

error:"Internal Server Error"
exception:"java.lang.Exception"
message:"There is already a user registered with the email provided"
path:"/registerAccountant"
status:500
timestamp:1523286158171

how do i extract that error message?

Below is my code to send and recieve

$.ajax({
        type: accountantRegistrationForm.attr('method'),
        url: accountantRegistrationForm.attr('action'),
        data: fd ,
        contentType: false,
        processData: false,
        success: function(data) {

            $('#accountantSubmitBtn').attr('disabled', false);
            //resetJournalEntryTable();

            setTimeout(function(){
                $.toast({
                    text: 'New Accountant successfully saved.!',
                    showHideTransition: 'fade',
                    hideAfter: 2000,
                    bgColor: '#3b78e7',
                    textColor: '#fff',
                    allowToastClose: false,
                    position: 'top-center',
                    icon: 'success',
                    loader:false
                });

                $('body').loading('stop');
                /*$('html, body').scrollTop(0);*/
            }, 500);

            //$('#jedatatable').DataTable().ajax.reload();
        },
        error: function(data) {
            setTimeout(function(){
                $.toast({
                    text: 'Accountant Registration failed.1 !',
                    showHideTransition: 'fade',
                    hideAfter: 2000,
                    bgColor: '#3b78e7',
                    textColor: '#fff',
                    allowToastClose: false,
                    position: 'top-center',
                    icon: 'error',
                    loader:false
                });

                $('body').loading('stop');
                /*$('html, body').scrollTop(0);*/
            }, 500);
            $('#accountantSubmitBtn').attr('disabled', false);
            $('body').loading('stop');
        },
    });
  • 写回答

1条回答 默认 最新

  • 关注

    Try something like this, it will throw the error message to the console screen.

    error: function (xmlHttpRequest, textStatus, errorThrown) {
            console.log(errorThrown)
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值
  • ¥15 VFP如何使用阿里TTS实现文字转语音?