1

I am trying to collect all the form data and send it as a XML to Controller. This XML will further be sent to back end which will take care of it.
There is no need to marshal this XML into an Object.After receiving this XML I just need to send a String success message back.
It is half working. I am able to receive XML message from UI page and able to print it on console. But when I just send success message back UI ajax call receives
No conversion from text to application/xml

@RequestMapping(value="/save",method=RequestMethod.POST,consumes={"application/json", "application/xml", "text/xml","text/plain"})
        @ResponseBody public String handleSave(@RequestBody String formData)
        {
            System.out.println("comes here");
            System.out.println(formData);
return "Success";

    } 

$('form').submit(function () {
                    $.ajax({
                        url: $(this).attr('action'),
                        type: 'POST',
                        processData: false,
                        data: collectFormData1(),

                        headers: {
                            "Content-Type":"application/xml"
                        },
                        dataType: 'application/xml',
                        success: function (data) {
                            alert('Success:'+data)
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            console.log('jqXHR:'+jqXHR+'\n'+'textStatus:'+'\n'+textStatus+'errorThrown::'+errorThrown);
                        }
                    });

                    return false;
                });
1
  • Do you know if your Spring MVC config is using org.springframework.http.converter.StringHttpMessageConverter as one of its HttpMessageConverters? Note that AnnotationMethodHandlerAdapter will use it by default if none are explicitly configured. You also might want to try setting the Content-Type of the response to text/plain. Commented Aug 12, 2013 at 15:24

1 Answer 1

3

Try to remove dataType: 'application/xml' from jquery code.

As mentioned in documentation: DataType: The type of data that you're expecting back from the server. (http://api.jquery.com/jQuery.ajax/)

Sign up to request clarification or add additional context in comments.

2 Comments

Do I need to remove headers: { "Content-Type":"application/xml" } too?
No. It is header of request to server. Not sure, but you can try to remove it if you remove consumes={"application/json", "application/xml", "text/xml","text/plain"} line from @RequestMapping

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.