jquery ajax调用jsp页面输入undefined

时间:2012-04-25 14:27:59

标签: javascript jquery html jsp

我通过处理下载文件的jQuery调用JSP页面。

$("#download").click(function(e){
    $.get("download.jsp", {filename:"file.txt"},doUpdate());
});

和我的doUpdate()是

function doUpdate(response){
    console.log('done with jsp ' + response);
}

响应未定义

我知道JSP页面正在运行,因为如果我对文件名进行硬编码,那么页面就会正确执行。

在jsp中,我使用以下命令获取文件名:

String filename = request.getParameter("filename");

我做错了什么吗?

2 个答案:

答案 0 :(得分:1)

是的,您没有将数据传递给该函数,请尝试:

$.get("download.jsp", {filename:"file.txt"}, doUpdate);

$.get("download.jsp", {filename:"file.txt"}, function(data) {
  doUpdate(data);
  // more stuff
});

答案 1 :(得分:1)

您严重引用处理函数

$.get("download.jsp", {filename:"file.txt"},doUpdate());

应该是

$.get("download.jsp", {filename:"file.txt"},doUpdate);

如果你离开()你正在执行函数,它是作为参数传递给get方法的返回值