Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用Spring MVC+进行文件夹遍历;AJAX_Jquery_Ajax_Spring_Spring Mvc - Fatal编程技术网

Jquery 使用Spring MVC+进行文件夹遍历;AJAX

Jquery 使用Spring MVC+进行文件夹遍历;AJAX,jquery,ajax,spring,spring-mvc,Jquery,Ajax,Spring,Spring Mvc,我有一个类似于云存储的应用程序。我有一个侧树,它看起来像windows资源管理器上的那个。它旁边是一个文件框,我想在其中显示我所在的特定文件夹的文件夹和文件 我有我的映射,它返回其中的文件夹和文件 例如localhost:8080/home/get files?folderId=4 @RequestMapping(value = "/get-files", method = RequestMethod.GET) public @ResponseBody FolderShowDto getFile

我有一个类似于云存储的应用程序。我有一个侧树,它看起来像windows资源管理器上的那个。它旁边是一个文件框,我想在其中显示我所在的特定文件夹的文件夹和文件

我有我的映射,它返回其中的文件夹和文件

例如localhost:8080/home/get files?folderId=4

@RequestMapping(value = "/get-files", method = RequestMethod.GET)
public @ResponseBody FolderShowDto getFiles(Principal principal, Integer folderId) {
    FolderShowDto folder = fileSystemService.getFolder(folderId, userDao.show(principal.getName()).getId());
    return folder;
}

如何在不使用Ajax重新加载页面的情况下更新文件盒?

您的Ajax调用应该是这样的:

$.ajax({
        url : "/home/get-files?folderId="+ currentFolderId,
        type : "GET",
        cache:false,
        success : function(resp) {
            // your data is here
        },
        error : function(jqXHR, textStatus, errorThrown) {
            // handle errors here
        }
    });

因为我使用@ResponseBody,所以我的控制器方法将以JSON的形式返回我的数据

$.ajax({
    dataType : "json",
    headers : {
        'Accept' : 'application/json',
        'Content-Type' : 'application/json'
    },
    type : 'GET',
    url : '/home/get-files',
    data : 'folderId=4',
    success : function(response) {
        // access my data here
    },
    error : function() {
        // what happens if there is an error
    }
});

如果您使用jquery,它应该是这样的:
$.ajax({url:/home/get files?folderId=4”,键入:“get”})您需要设置一个时间间隔,以每1秒调用一次ajax,并根据新结果更新视图。如何访问映射返回的数据?谢谢,我基于此编写了代码,并完成了后续操作。我发布了有效的代码。