samedi 1 août 2015

How to Get Ajax value

I am using ajax call for my onclick event in a table. I am returning an object from controller. And I need to show that value in alert.

My page table td as follows,

    <td onClick="img('${matched.transaction.id}')" id="ss"><input class="group_btn" type="submit" name="submit"
                                            value="View" id="groupbtn" style="vertical-align: super;" /></td>

Ajax call written in script,

    <script>
        function img(trId) {
            $.ajax({
                type : "GET",
                async : false,
                url : "getImage.htm",
                data : "trId=" + trId,
                success : function(data) {
                    obj = jQuery.parseJSON(data);
                }
            });
        }

    </script>

my controller class, which returns the value,

    public class GetImageController extends AbstractController {

        @Resource
        private CommonRepository commonRepository;

        public ModelAndView handleRequestInternal(HttpServletRequest request,
                HttpServletResponse response) throws Exception {
            ModelAndView modelAndView = new ModelAndView("ajax_foo");       
            String trId = request.getParameter("trId");     
            if (!trId.equals("")) {
                return save(request, response);
            }
            return save(request, response);
        }

        ModelAndView modelAndView = new ModelAndView();

        private ModelAndView save(HttpServletRequest request,
                HttpServletResponse response) throws Exception {

            String trId = request.getParameter("trId");     
            TransactionDocument trDoc = commonRepository.find(TransactionDocument.class, "transactionId", Long.parseLong(trId));
            Document doc = commonRepository.find(Document.class, "id", trDoc.getDocumentId());      
            String imagePath = doc.getDocPathServer();
            String imageName = imagePath
                    .substring(imagePath.lastIndexOf("/") + 1);
            String imageUrl = new AWSS3Helper().doGenerateUrl(imageName);   

            System.out.println("imageUrl-----"+imageUrl);       

            modelAndView.addObject("imageUrl", imageUrl);

            return modelAndView;
        }   

    }

I just want to show the imageUrl value in javascript alert. I am able to see the value in catalina.out(sysout).

can anyone tell me a way on how to show that value in alert?

Aucun commentaire:

Enregistrer un commentaire