Search code examples
ajaxjspdatatablestruts2

How to set s:param value in Ajax success body in Struts 2


How can I set <s:param> value in Ajax success body?

I load a data with Ajax call and I fetch it into datatable but when I want to set s:param value I can not get its value, below is my code:

 $.ajax({
        url: "dataPp",
        type: 'POST',
        dataType : 'JSON',
        success: function (res) {
            table = $('table#dttable1').DataTable();
            table.clear();
            $.each(res.dokpp, function(i, item){
                var json = res.dokpp[i];
                table.row.add(
                    [json["kodeDok"],
                    json["fileNameUi"],
                    json["depPenerbit"],
                    json["createdDate"],
                    json["tglBerlaku"],
                    json["tglKadaluarsa"],
                    json["urutRev"],
                    '<s:url var="prev" namespace="/mr" action="prevDasboard">'+
                        '<s:param name="file">'+json["fileName"]+'</s:param>'+
                    '</s:url>'+
                    '<a href="${prev}" class="btn btn-default btn-xs">preview</a>'
                ]);
                console.log(json["fileName"]);
            }); 
            table.draw();
        }
    });

Solution

  • I fixed this with this code :

    '<a href="mr/prevDasboard?file='+json["fileName"]+'" class="btn btn-default btn-xs">preview</a>'
    

    I use html tag to create a href.