Javascript 使用ajax将值放入SpringMVC中的引导模式弹出字段值中,以从数据库获取数据
我需要使用ajax从SpringMVC中模式弹出字段内的数据库中获取值。我认为,我们需要使用javascript将值放在模式弹出字段中Javascript 使用ajax将值放入SpringMVC中的引导模式弹出字段值中,以从数据库获取数据,javascript,twitter-bootstrap,spring-mvc,Javascript,Twitter Bootstrap,Spring Mvc,我需要使用ajax从SpringMVC中模式弹出字段内的数据库中获取值。我认为,我们需要使用javascript将值放在模式弹出字段中 非常感谢您的帮助 您可以尝试在模式中调用自定义url,如下所示: function load_modal(ev){ if (ev && ev.preventDefault) ev.preventDefault(); // prevent navigation var url = "" //construct you
非常感谢您的帮助 您可以尝试在模式中调用自定义url,如下所示:
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>
试试看。使用spring MVC+Bootstrap对我很有效谢谢您的建议。
@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;
}