[英]Place values inside bootstrap modal popup field value in spring MVC using ajax to get the data from database
我需要使用ajax从Spring MVC的模式弹出字段中的数据库中获取值。 我认为,我们需要使用javascript将值放在模式弹出窗口中。
帮助高度赞赏!!!!
您可以尝试在模式内部调用自定义网址,如下所示:
function load_modal(ev){
if (ev && ev.preventDefault)
ev.preventDefault(); // prevent navigation
var url = "" //construct your url with all parameters that you need
//avoid cache
url +="&_="+(new Date()).getTime()
$("#modal").load(url, function() { // load the url into the modal
$(this).modal('show'); // display the modal on url load
});
return false; // prevent the click propagation
}
该url在服务器端调用操作,并在结果页面中填充所需的数据,该结果页面将以模式显示
您可以使用以下javascript代码进行Ajax调用并将值放在字段中
<script type="text/javascript">
function ajaxLink(url, params, displayComponentId) {
$.post(url, params, function(data) {
document.getElementById('fieldId').value =data.name;
});
}
function onClickMethod(val){
ajaxLink('/myProject/getTags', {'tagName': val}, 'viewDiv');
}
</script>
fieldId应该是相应字段的ID。
在服务器端内部,您必须在spring MVC中遵循以下代码
@RequestMapping(value = "/getTags", method = RequestMethod.POST)
@ResponseBody public User getTags(@RequestParam("tagName") String
tagName)
{
User user=new User();
//Write a method to access the data from DB
user.setName("test")
return user;
}
试试吧。 它适用于Spring MVC + Bootstrap
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.