使用AJAX发送FILE并刷新表

时间:2015-04-15 13:47:26

标签: jquery ajax spring

您好我尝试使用ajax发送文件并将此文件复制到我的服务器中,但我不知道如何使用ajax调用的响应刷新我的表。这是我的代码:

//这是我的功能

function upload(){
var sampleFile = document.getElementById("file").files[0];
var formdata = new FormData();
formdata.append("sampleFile",sampleFile);

var xhr = new XMLHttpRequest();
xhr.open("POST","upload.htm", true);
xhr.send(formdata);

xhr.onreadystatechange = function(data) {
    if (xhr.readyState==4 && xhr.status==200) {
         $('#table').html(data);//data always is empty i dont know how i get the list for refresh my table

    }   
};  

}

//这是我的控制器

@RequestMapping(value="/upload.htm", method = RequestMethod.POST)
public Set<Object> upload(@RequestParam("sampleFile") CommonsMultipartFile file, HttpServletRequest request, HttpServletResponse response)
         {if (!file.isEmpty()) {
        try {

            //Copy file in server

    //Getting set<Object>



        }
        catch(Exception e){
        //thow exception

        }
      //return set<Object>
    }
}

0 个答案:

没有答案