开发者

JSON object returned as file download (Spring MVC)

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜