简体   繁体   中英

How to make ajax get call for text to Java controller in Spring MVC?

I am expecting a BigDecimal.toString() value from Web call.

But i am not manage to configure it and getting either 404-Not found or 406.

Following is Spring MVC Code

 @RequestMapping(value="get/myData", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
 @ResponseBody
 public String getMyData(@ModelAttribute("user") User user, 
      @ModelAttribute("detailForm") DetailForm form)
 {
  //A web service called return big decimal and return that big decimal value toString
   return "Value";
 }

Following is calling code:

  var convId = $("#" + $("body form:first").attr("id")).find('input[name="_CONV_ID"]').val();



 blockUI: false,
            dataType: 'text',
            type: 'GET',
            url: "get/myData.do",
            data: { '_CONV_ID': convId},
            success: function (data) {
                // new dialog
                alert(data);
            },
            error: function (result) {
                alert("Error" + result);
            }

Could anyone please help me in adjusting code. On button click, a value is getting return from web service which is of BigDecimal type

Trying reaching the url http://localhost:8080/your_application_name/get/myData . If you find 404 error there, you need to check your web.xml. Check the section of servlet-mapping part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM