根据控制器返回的属性捕获ajax响应

时间:2018-08-10 18:58:43

标签: javascript jquery json ajax spring-mvc

  

我有一个如下的ajax函数:

$.ajax({// defining the below function as ajax responsive//
    url:'Type&State', // the function that process the  mapped url name and matching type is going to receive the data//
    type:'POST',
    data:{state_name:name,case_type:type},// function to get the value from jsp page and send it to mapped class function//
    success: function(response){// if the backend process is success then the function will run by getting the response as its parameter//
            alert(response.message);
            load();
    },
    error: function(response){
          alert("unable to pull up any electricians or plumbers for the selected state");
                        }   
});         

}

load = function(){  
    $.ajax({
        url:'list',
        type:'POST',
        success: function(response){
                data = response.data;
                $('.tr').remove();
                for(i=0; i<response.data.length; i++){                  
                    $("#table").append("<tr class='tr'> <td> "+response.data[i].user_name+" </td> <td> "+response.data[i].user_email);
                }           
        }               
    });
  

现在,根据用户输入,我的控制器可能会重新调整用户数据或   管理员数据,我知道如何捕获用户数据(电子邮件和姓名),但它可能   不返回用户数据类型,所以任何人都可以告诉我如何配置成功或加载功能   在响应包含管理属性时打印管理数据的响应,以及在响应包含用户属性时如何打印用户数据,谢谢!

0 个答案:

没有答案