[英]ajax call from view to controller in Play framework
I am newbie to MVC and Play framework (Java). 我是MVC和Play框架(Java)的新手。 Instead of using Groovy for dynamic HTML, I made our own page with static HTML, I mean we haven't any Groovy expressions.
我没有使用Groovy生成动态HTML,而是使用静态HTML创建了自己的页面,这意味着我们没有任何Groovy表达式。 Here, I have a controller "Customer", generates JSON object which has to be sent to an ajax call in view.
在这里,我有一个控制器“ Customer”,生成了JSON对象,该对象必须发送到视图中的ajax调用。 I tried with render() method, seems I haven't used correctly.
我尝试了render()方法,似乎我使用不正确。 can you give me some idea to forward from here.
你能给我一些想法从这里转发吗? thanks.
谢谢。
public static void customer(){
WordAPI objWordAPI=new WordAPI();
List<WordInfo> listObjWord= objWordAPI.MakeAPIObject(nSurveyId);
JSONSerializer modelSerializer=new JSONSerializer().exclude("NSpontanity","NWordRepresentativity","NWordValue","NWordFrequency","class").rootName("Words");
render("Application/wordcloud.html",modelSerializer.serialize(listObjWord));
}
and ajax call in view "wordcloud.html" 和ajax调用视图“ wordcloud.html”
$.ajax({
url: "/customer",
dataType : 'json',
success: function (data) {
alert(data);
}
})
I believe this should work: 我相信这应该有效:
public static void customer(){
WordAPI objWordAPI=new WordAPI();
List<WordInfo> listObjWord= objWordAPI.MakeAPIObject(nSurveyId);
JSONSerializer modelSerializer=new JSONSerializer().exclude("NSpontanity","NWordRepresentativity","NWordValue","NWordFrequency","class").rootName("Words");
renderJSON(modelSerializer.serialize(listObjWord));
}
I've never used rootName before, I usually just do something more like this: 我以前从未使用过rootName,我通常只是这样做:
public static void refreshNotifications()
{
JSONSerializer notifySerializer = new JSONSerializer().include("message","notifyId","class").exclude("*");
List<Notification> notificationList = user.getNotifications();
renderJSON(notifySerializer.serialize(notificationList));
}
Side Note: With refreshNotifications I have a Security method I run before which verifies and populates the user object. 旁注:使用refreshNotifications时,我运行了一个Security方法,该方法将验证并填充用户对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.