Problems with Post methods 400 and 404 in Ajax

Source: Internet
Author: User

1. Change from 400 to 404

I believe that a lot of people have used Ajax technology to get the data, usually using get to get, but the sensitive information can not continue to use get, and then replaced by post, but sometimes when using post, some strange things happen, such as direct access is 400, Plus header and data access is 404, which is confusing, why not from the beginning of the error 404?

Reason for 2.400

400 in the HTTP status code means that the server does not understand your request, this time you should check your request format, because post is the header and body (data) submitted, if you do not have the header then the error is normal, Check the header can be used postman this Google plug-in to check, this plugin can tell you what parameters are missing or is the correct format, the use of the method will not repeat the proposal Baidu. The general header format is as follows

The following is the header of the HTTP format

Reason for 3.404

If you add the head but 404, then do not panic, this time you have requested success, but only data 404 and to, do not see the page is written 404 on the Panic, this time you should pay attention to their body (data) content, read the HTTP should understand, the header is the request header, Body inside is the real data, the data does not look for things, and the format is generally special, you have to consult with the backstage body format problem, is a string or object body, here I give two examples, the following is the object format

This is the data format for the console output:

Here if your background is to accept the format of the string, then you will be error 404, then you should change the format, you should use the object json.stringify the body (data) into a string format,

Here's the data if you can find out the format of it is:

Here is a simple string concatenation, if you have time you can even spell a string of characters and then when the body passes through

This article original, reproduced please indicate the source

Problems with Post methods 400 and 404 in Ajax

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.