2012-04-25 115 views
0

我正在通過處理下載文件的jQuery調用一個JSP頁面。jquery ajax調用jsp頁面輸入undefined

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

和我doUpdate()是

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

反應是不確定的

我知道JSP頁面,因爲工作,如果我硬編碼的文件名的頁面正確執行。

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

我是否正確做的事情:

在JSP我用得到的文件名?

回答

1

你引用的處理函數嚴重

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

應該是

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

如果你離開()你正在執行的函數,它是作爲參數傳遞給get方法的返回值

+0

謝謝你,這是問題 – 2012-04-25 14:33:56

1

是的,你是不是傳遞數據的功能,嘗試:

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

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

謝謝你的快速響應! – 2012-04-25 14:34:07