$('.remove_proposal_file').unbind('click').bind('click', function(){
var file_row_id = $(this).attr('fileid');
var obj = $(this);
$.ajax({
url : '<?=base_url();?>project/remove_proposal_file',
method: 'POST',
data: {
frow_id: file_row_id,
action: 'remove_file_supplier',
'<?=$csrf['name'];?>': '<?=$csrf['hash'];?>'
},
success: function( data ) {
var arr = $.parseJSON(data);
if(arr['status'] == 1 ){
$(obj).parent().remove();
$('.file_remove_msg').show();
setTimeout(function(){ $('.file_remove_msg').hide(); }, 7000);
}
click_handler();
}
});
});
以上代码是为删除单个文件而编写的。我想删除多个文件,以便如何删除?
答案 0 :(得分:0)
我认为您在询问如何从浏览器发出多个AJAX请求以逐个删除文件。但是,这是错误的做法。
目前,您正在通过import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class ShellFromJava {
public static ArrayList<String> command(final String cmdline,
final String directory) {
try {
Process process =
new ProcessBuilder(new String[] {"bash", "-c", cmdline})
.redirectErrorStream(true)
.directory(new File(directory))
.start();
ArrayList<String> output = new ArrayList<String>();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ( (line = br.readLine()) != null )
output.add(line);
if (0 != process.waitFor())
return null;
return output;
} catch (Exception e) {
//Warning: doing this is no good in high-quality applications.
//Instead, present appropriate error messages to the user.
//But it's perfectly fine for prototyping.
return null;
}
}
public static void main(String[] args) {
testHandler("curl http://stackoverflow.com");
}
static void testHandler(String cmdline) {
ArrayList<String> output = command(cmdline, ".");
if (null == output)
System.out.println("\n\n\t\tCOMMAND FAILED: " + cmdline);
else
for (String line : output)
System.out.println(line);
}
}
单独删除文件:
post
相关文件参数为:
url: <?=base_url();?>project/remove_proposal_file
我建议您实现一个服务器端点来删除多个文件,如下所示:
frow_id: file_row_id
并提供一系列的皱眉:
url: <?=base_url();?>project/remove_proposal_files
为了做到这一点,您需要确保您的界面允许选择多个文件,然后您可以编写一个jQuery语句来读取选择的文件。这将构成我建议的新端点的输入数组的基础。