Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return more than one value to jQuery.Ajax success function

Tags:

jquery

I'm trying to return more than one value to jqueryAjax success but failed to do so. this what I have done so far......

 String emp = request.getParameter("ID");
    ArrayList<String> al = new ArrayList();
    al=ur.editLeave(emp);
    String cl = al.get(0);
    out.print(cl);
    out.print(al.get(1));
    out.print(al.get(2));

from this jsp page I try to return 3 values.

$.ajax({
    type: "GET",
    data: 'ID=' + idel,
    async: false,
    url: "ForleaveMaster.jsp?Eleave=l",
    success: function(cl, ml, ot) {
        alert(cl, ml, ot);
        $('input[id=ELM_CL]').val($.trim(cl));
        $('input[id=ELM_ML]').val($.trim(cl));
        $('input[id=ELM_OT]').val($.trim(cl));
    },
    error: function() {}
});

Please help me out.

like image 534
Sudarshan Avatar asked Jan 19 '26 10:01

Sudarshan


1 Answers

Everything you return is passed as a first argument to your function.

$.ajax({
    type: "GET",
    data: 'ID=' + idel,
    async: false,
    url: "ForleaveMaster.jsp?Eleave=l",
    success: function(data) {
        var array_data = String(data).split("\n");
        var cl = array_data[0],
            mt = array_data[1],
            ot = array_data[2];
        alert(cl,ml,ot);
        $('input[id=ELM_CL]').val($.trim(cl));
        $('input[id=ELM_ML]').val($.trim(cl));
        $('input[id=ELM_OT]').val($.trim(cl));
    },
    error: function() {                        
    }
});
like image 128
mishik Avatar answered Jan 21 '26 02:01

mishik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!