我目前有一个拥有此代码的jqgrid,直到我将数据传递到ajax帖子时才会运行
$("#getSelected").click(function(){
var ids = grid.jqGrid('getGridParam','selarrrow');
if (ids.length>0) {
var names = [];
for (var i=0, il=ids.length; i < il; i++) {
var name = grid.jqGrid('getCell', ids[i], 'Name');
names.push(name);
}
//alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
$("#names").html(names.join(", "));
$("#dialog-confirm").dialog({
height:280,
modal:true,
buttons:{
'Cancel': function(){
$(this).dialog('close');
},
'Confirm': function(){
// alert("Confirm");
//alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
$.ajax({
type: "POST",
url: "/MyController/downloadFile/",
data: { method: "downloadFile",
orderNum: JSON.stringify(ids),
names: JSON.stringify(names)
},
dataType: "json",
success: function(msg){
alert(msg);
},
error: function(res, status, exception) {
alert(res);
}
});
}
}
});
}
});
然后我想发布数据并在我的控制器方法中获取它。控制器方法是downloadFile,我想要它做的就是将所有名称写入文件。这是我目前工作的downloadFile版本
def downloadFile =
{
def date = new Date()
SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy")
File file = File.createTempFile("MyData",".txt")
file.write("hello world!")
String MyTitle = "ChangeMe" + sdf.format(date).toString()
response.setHeader "Content-disposition", "attachment; filename=${MyTitle}"
response.contentType = 'text-plain'
response.outputStream << file.text
response.outputStream.flush()
}
有什么想法?感谢