如何从控制器发送值,并将其显示在div中 [英] How do I send value from controller, and display it in a div
本文介绍了如何从控制器发送值,并将其显示在div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检索控制器发送的值。我无法找到错误。
$(document).ready(function(){
$( #name)。val( < span class =code-string> welcome);
$( button )。click(function(){
var n = $( #name)。val();
$ .ajax({
type: post,
url: $ {pageContext.request.contextPath} / direct,
data:{name:n},
success:function(data){
// displayfromcontroller();
$( 。display_area)。html(data);
alert( 即将发生的值= +数据);
},
错误:function()
{
alert( 错误);
}
});
});
})
这是我的控制器。我已经尝试返回视图的名称,尝试返回map。
@ RequestMapping( value = / direct,method = RequestMethod.POST)
public String direct(HttpServletRequest请求,HttpServletResponse
响应){
字符串 fullname = request.getParameter ( name);
系统。 out .println( hehjgeuqg ; qg; + fullname);
/ * model.addAttribute(name,fullname); * /
Map< String,String> loPageFields = new HashMap< String,String>();
loPageFields.put( status,fullname);
字符串 fname = loPageFields。 get ( status);
系统。 out .println(fname);
return loPageFields。 get ( status);
// 返回fname;
}
我尝试了什么:
我试过返回一个视图,映射和来自控制器的字符串。
每当我返回一个视图时,该特定视图的整个代码都显示在display_area div标签中。每当我尝试返回String时,它进入成功块,但只显示警告为即将发生的值=。
解决方案
(文件).ready(function(){
( #name)。val( welcome);
( button)。click(function(){
var n =
I am trying to retrieve the value sent by a controller.I am unable to find the mistake.
$(document).ready(function(){
$("#name").val("welcome");
$("button").click(function(){
var n = $("#name").val();
$.ajax({
type:"post",
url:"${pageContext.request.contextPath}/direct",
data:{name : n},
success:function(data){
//displayfromcontroller();
$(".display_area").html(data);
alert("coming value = " + data);
},
error:function()
{
alert("Error ");
}
});
});
})
This is my controller. I have tried returning name of a view, tried returning map.
@RequestMapping(value = "/direct", method = RequestMethod.POST)
public String direct(HttpServletRequest request,HttpServletResponse
response) {
String fullname=request.getParameter("name");
System.out.println("hehjgeuqg;qg; "+fullname);
/*model.addAttribute("name", fullname);*/
Map<String, String> loPageFields = new HashMap<String, String>();
loPageFields.put("status", fullname);
String fname=loPageFields.get("status");
System.out.println(fname);
return loPageFields.get("status");
//return fname;
}
What I have tried:
I have tried returning a view, map and a string from the controller.
Whenever I return a view whole code of that particular view is being displayed in the display_area div tag. Whenever i tried returning String it enters success block but just displays the alert as "coming value= ".
解决方案
(document).ready(function(){
("#name").val("welcome");
("button").click(function(){ var n =
这篇关于如何从控制器发送值,并将其显示在div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文