Home Struts 2 set s:param value in ajax success body
Reply: 2

Struts 2 set s:param value in ajax success body

muammar ali
1#
muammar ali Published in 2018-01-13 05:03:49Z

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();
        }
    });

thank you.

muammar ali
2#
muammar ali Reply to 2018-01-13 05:44:51Z

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.

Roman C
3#
Roman C Reply to 2018-01-13 23:53:01Z

When you use <s:param> tag the value is not yet available. Struts tags are executed on server when JSP is rendered, but ajax is a javascript code which is executed on the client's browser after response is returned from the server. The server can't know what the value is substituted by the client.

You can render url without parameter and then add it dynamically.

var url = '<s:url var="prev" namespace="/mr" action="prevDasboard"/>?file='+json["fileName"];
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.37048 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO