JQuery ajax 返回值如何进行赋值

问题如下
ajax提交请求获得的数据我把它附给一个var变量,但老是报一个错误,没有对象

网上资料:
这个$.ajax可以有返回值的,返回值是xmlhttprequest对象
是为了能够让返回值正确赋值,你必须把ajax设置为同步的,而非异步的。
async :false

 

js代码:

var old = "";
$.ajax({       
type:"POST",
url:"http://127.0.0.1:8080/PeugeotRace/MgmtLoginServlet.do?action=query",
data:"id="+newsids[i].value,
//防止自动转换数据格式。
     async :false,
success:function(msg){ 
old = msg;
}    
});


 

 

java代码:

if ("query".equals(action)) {
String id = request.getParameter("id");
if (UtilTool.isNotBlank(id)) {
INoticeService noticev = new RgNoticeServiceImpl(); 
try {
RgNotice notice =noticev.getoneRecord(id);
if(notice!=null){
PrintWriter out = response.getWriter();
//输出数据
out.println("添加日期:"+notice.getVotetime().toString().substring(0, 11)+"<br>内容:"+notice.getContent());
out.flush();
out.close();
} 
} catch (Exception e) {
e.printStackTrace();
} 
}
}


 

posted on 2011-12-08 15:57  dqsweet  阅读(1193)  评论(0编辑  收藏  举报

导航