在控制器将数据发送到jsp之后,如何启动脚本
How to start a script after that the controller sends data to jsp
我有index.jsp。这个jsp调用控制器:
@Controller
public class CustomerController {
//Other code..
//..
String customerJSON = null;
ModelAndView model = new ModelAndView("index", "customerJSON", customerJSON);
return model;
}
customerJSON是一个包含JSON信息的字符串。
Controller返回customerJSON给jsp。
现在,在jsp中,我想将customerJSON显示到一个警报中。
在jsp中添加:
<script>
var customer = "<c:out value='${customerJSON}'/>";
alert(customer);
</script>
问题是,这个警告在页面加载时开始,而不是在控制器返回到jsp时开始。
如何在控制器调用后显示警报,而不是在加载页面时显示警报?
我会像这样实现你的控制器方法(和requestmapping):
@RequestMapping(value = "/getCustomer")
public @ResponseBody Customer getCustomer() {
Customer c = new Customer();
//do whatever is needed to init customer data
return c;
}
如果你有jackson作为依赖项,它会为你处理json序列化。
那么你的javascript(使用jquery)代码可能看起来像这样:
<script>
$.getJSON("getCustomer", data, function (result)
{
alert(result);
});
</script>
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- Meteor上的启动页面
- 如何防止网页加载后自动启动功能
- 如何从JavaScriptInterface启动Navigation Drawer
- window.on.scroll事件未启动
- 单击按钮后启动javascript提示
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- spine.js在启动时填充模型实例
- 如何在所有ng点击事件AngularJS上启动一个方法
- jQuery悬停在没有鼠标悬停的情况下启动
- SignalR客户端启动连接时如何设置用户
- Meteor:在启动时将html注入客户端文件
- Angular UI启动日期选择器问题
- 如何用低音量自动启动Youtube视频(iframe)
- jQuery mouseup在拖离链接后未启动
- 你如何在 React-Native 中为 android 制作启动/启动画面
- iPad触摸启动启动两次
- Phonegap iPad应用程序启动/启动屏幕切换在devicereready