开发者

How to Handle the response from server after a form submission?

开发者 https://www.devze.com 2023-04-08 12:12 出处:网络
I\'m attempting to create ajax functionality to a form that uploads files.I created the isolated iframe and target the form submission to it.The server validates the files and sends back an XML doc in

I'm attempting to create ajax functionality to a form that uploads files. I created the isolated iframe and target the form submission to it. The server validates the files and sends back an XML doc in the response body. How would I handle and retrieve the XML doc on the client side, preferably using JavaScript?

This is my handler,

@Controller
@RequestMapping("/upload")
public class UploadController {


@RequestMapping(method = RequestMethod.POST)
public String handleFileUpload(HttpServletResponse response, @RequestParam("file") MultipartFile file) throws IOException{
    response.setContentType("text/xml");
    response.se开发者_运维问答tHeader("Cache-Control", "no-cache");
    response.getWriter().write("<test>hello</test>"); 
    return null;
}
}


We do something similar but return JSON instead of XML. That JSON is then used as-is by the JavaScript function that triggers the upload ----

If i use the response type as json in the iframe form submit for file upload..i am seeing a download popup asking me to save or open... the application/json response is handled by the browser as a download ... issue occurs in IE and older versions of FF


There were several suggestions on using a hidden iframe on the net. That's what my final attempt was, I sent an xml doc to the iframe's body and manage the data from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消