开发者

JSON object returned as file download (Spring MVC)

开发者 https://www.devze.com 2023-02-01 02:39 出处:网络
Instead of loading my JSP, the JSON object is returned as file download. Here\'s my Controller method

Instead of loading my JSP, the JSON object is returned as file download. Here's my Controller method

@RequestMapping(value="/newProduct", method=RequestMethod.GET)public @ResponseBody ProductDetails getNewProductForm(@RequestParam String categoryName) {

ProductDetails product = new ProductDetails(); product.setCategoryName(categoryName); return product;}

And when i open the file to download, this is what is open as text file.

{"price":null,"productCode":null,"categoryName":"electronics","name":null,"id":null,"description":null}
开发者_Python百科

Could there be something wrong with my JSON jsp file? or is JSON not well configured on servlet-config. The method getNewProductForm was called from URI hyper link. Does JSON return the product object using the same URI?


You have to let jQuery know to expect a JSON response back from the server, i.e. use the $getJSON function for a GET, or something like this for a POST:

$.post(url, $("#myForm").serialize(),
  function(data) {
    alert('data');
}, "json");
0

精彩评论

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