function rename(id, name) { window.scroll_top = $(window).scrollTop(); var path = pathJoin([name,".."]); var basename = get_basename(name); var new_name = prompt("Enter the new name for this element.", basename); if (new_name != null) { new_name = pathJoin([path, new_name]); var data = new FormData(); data.append("new_name", new_name); var csrf_token = document .querySelector("meta[name='csrf-token']") .getAttribute("content"); var csrf_param = document .querySelector("meta[name='csrf-param']") .getAttribute("content"); if (csrf_token && csrf_param) { data.append(csrf_param, csrf_token); } $.ajax({ url: '/admin/file_managers/' + id + '/rename', method: 'PUT', data: data, headers: { // 'Content-Type': 'multipart/form-data', // 使用 multipart/form-data 在此不需要設定 Content-Type。 'X-Requested-With': 'XMLHttpRequest', 'Authorization': `Bearer ${ csrf_token }`, }, contentType: false, //required processData: false, // required mimeType: 'multipart/form-data', statusCode: { 204: reload_explorer_section, 403: function() { alert( "Rename failed!\nFile exist!" ); } } }) } return false; }