简体   繁体   English

在Ajax调用中返回实体对象而不是String

[英]Return Entity Object instead of String in Ajax call

I am developing a web portal using Freemarker(FTL) as front end technology. 我正在开发一个使用Freemarker(FTL)作为前端技术的门户网站。 The complete project is based on single ftl page and have used wizard to process different kind of user request.In Back end I have used Spring MVC pattern where controller will process user request.I am using AJAX call to navigate on wizard and display data on screen. 整个项目基于单个ftl页面,并使用向导处理不同类型的用户请求。在后端我使用了Spring MVC模式,其中控制器将处理用户请求。我正在使用AJAX调用导航向导并显示数据屏幕。

On click button a java script function is called which further uses ajax to call controller method . 在单击按钮上,调用java脚本函数,该函数进一步使用ajax来调用控制器方法。 The controller method perform some business logic and returns desired data. 控制器方法执行一些业务逻辑并返回所需的数据。

Now My requirement is to display ajax call data in particular division of FTL page. 现在我的要求是在FTL页面的特定分区中显示ajax调用数据。 I am using @ResponseBody to return JSON respose to ajax call. 我正在使用@ResponseBody将JSON respose返回给ajax调用。

I am using below ajax method as of now to load data in particular division of my screen.However Here I need write HTML tags in Java script section in order to load content. 我现在使用下面的ajax方法在我的屏幕的特定部分加载数据。但是,我需要在Java脚本部分中编写HTML标记以加载内容。 But I do not want to write HTML tags in this Ajax call section. 但是我不想在这个Ajax调用部分中编写HTML标记。 I want to return Object from ajax call and use proper FTL tags on required division to get and load data. 我想从ajax调用返回Object,并在所需的分区上使用正确的FTL标记来获取和加载数据。 Being very specific - $("#result").html(respContent); 非常具体 - $(“#result”)。html(respContent); part is giving me option to return a HTML page. 部分给我提供返回HTML页面的选项。 But i want to return a Object/Entity which can be parsed in FTL tags. 但我想返回一个可以在FTL标签中解析的对象/实体。

Many Thanks in Advance 提前谢谢了

       $.ajax({
        type : "GET",
        cache:false,
        url : "home",
        data : {},
        success : function(mwaCatlogueProfile) {
            alert('data : '+ mwaCatlogueProfile);
            console.log("SUCCESS: ", mwaCatlogueProfile);

            var respContent = "";
            respContent += "<span class='success'> <b>Please find server list:</b>";
            respContent += " </br>";
            respContent += mwaCatlogueProfile.environment + "</span>";

            $("#result").html(respContent);
            wizard.show();
        },

As FreeMarker is a server-side technology, the AJAX method had to return HTML that was rendered with FreeMarker on the server-side. 由于FreeMarker是服务器端技术,因此AJAX方法必须返回在服务器端使用FreeMarker呈现的HTML。 So all your templates remain on the server side, only some is used in normal responses, and some in AJAX responses. 因此,所有模板都保留在服务器端,只有一些用于正常响应,有些用于AJAX响应。 Of course, if the AJAX service called is not specialized on serving your UI, then this won't work, and you have to look for a JavaScript template engine. 当然,如果调用的AJAX服务不是专门为您的UI提供服务,那么这将不起作用,您必须寻找JavaScript模板引擎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM