Cause Analysis and Solution for 415 error in json format data uploaded by Ajax to the background, json415

Source: Internet
Author: User

Cause Analysis and Solution for 415 error in json format data uploaded by Ajax to the background, json415

Problem description:

Error 415 when ajax uploads a json-format datagram to the background, as shown in

Page code

function saveUser(){var uuId = document.getElementById("uuid").value;var idCard = document.getElementById("idCard").value;alert(uuId+idCard);// var result = new Object();// result.uuId = uuId;// result.idCard = idCard;// var saveData = JSON.stringify(result);// alert(saveData);$.ajax({url : "xdds/saveUser.do?random=" + Math.random(),type : "post",data : {"uuid" : uuId,"idCard" : idCard},// data:saveData,dataType : 'json',// contentType : "application/json",success:function(data){}});}

Background code

@RequestMapping(value = "/saveUser.do", method = { RequestMethod.POST })@ResponseBodypublic Map<String, Object> saveUser (@RequestBody MapUser user){Map<String, Object> map = new HashMap<String, Object>();System.out.println(user.getUuid()+user.getIdCard());map.put("result", "fda");return map ;}

Error Analysis: 415 (unsupported media type) request format is not supported by the request page

The correct json format {key: value, key: value} key and value should both contain double quotation marks. The data value in the preceding front-end code data does not contain double quotation marks, so an error is reported (because the previously accessed project is correct)

Therefore, preliminary analysis may be about the framework. Some frameworks can

Data: {"uuid": uuId, "idCard": idCard} is encapsulated in the correct json format.

I still don't know the specific reason. The blogger is also Tom. I will share it with you when the blogger understands it.

Solution: Open the Code Annotated at the front end

Var saveData = JSON. stringify (result) <br> this function can be converted to a real json format. <Br> ps: please correct me if something is wrong.

The above section describes the Cause Analysis and Solution for the 415 error in uploading json data to the backend Using Ajax. I hope this will help you, if you have any questions, please leave a message. The editor will reply to you in time!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.