Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Spring MVC: Receive XML data and Send String message back

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;
                });

Upvotes: 1

Views: 2036

Answers (1)

yname
yname

Reputation: 2245

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/)

Upvotes: 3

Related Questions