Ajax post data is not available, notice the Content-type settings post/get

Source: Internet
Author: User
Tags json

Ajax post data is not available, pay attention to Content-type settings, Post/get
About the JQuery data pass. Online access to a variety of data, garbled and so on.
Well, I also met today, online a look at a variety of entanglements. garbled, regardless of the first look to get no data.
Because the parameter has been passed in the way of jquery Ajax get, the ContentType value has not been set by default.

var Skip = 49; Number of skipped row
var Take = 14; //
function Load (Skip, Take) {
$ (' #divPostsLoader '). html (' ");
Send a query to server side to present new content
$.ajax ({
Type: "Get",
URL: "Ajaximage.ashx",
Data: {skip:skip, take:take},
ContentType: "Application/json; Charset=utf-8 ",//(CAN)
ContentType: "Text/xml",//(CAN)
ContentType: "application/x-www-form-urlencoded",//(CAN)
DataType: "String",
Success:function (data) {
if (Data!= "") {
$ ('. Thumb '). append (data);
}
$ (' #divPostsLoader '). empty ();
}
})
};

Chrome, without setting the ContentType value, OK, let's look at the default:



The default parameter is passed through the URL parameter, the requested content type: application/x-www-form-urlencoded

General processing file get parameter content:

int Skip = Convert.ToInt32 (context. request["Skip"]); 2:int Take = Convert.ToInt32 (context. request["Take"]);

There's no pressure, because I've been doing this all the time laughing, without any problems. All right, let's change the content type of the request:
ContentType: "Application/json; Charset=utf-8 ",//(CAN) 2://contenttype:" Text/xml ",//(CAN)


can also be, parameters get normal.
This is what we say get way, the parameter is followed by the URL, and Content-type Independent.



But today we have to post the way there are wood.

$.ajax ({2:type: "post"),
Chrome, the ContentType value is not set, to see the default:



Data is submitted by the from form, the requested content type: application/x-www-form-urlencoded,

OK, the general processing file fetch parameters are also available by default.

However, but I began to set the ContentType: "Application/json;" Charset=utf-8 ", look at the picture:



What is the Request paload???

Debug, look at our from inside, there is no content:



Well, here we solved the question in the Bo question (http://q.cnblogs.com/q/11342/),

Originally search to this Bo asked, is very happy, but, unresolved there are wood, small partner is not kind Ah! Laugh

After testing:

ContentType: "Application/json; Charset=utf-8 ",//(not allowed)
ContentType: "Text/xml",//(not allowed)
ContentType: "application/x-www-form-urlencoded",//(CAN)



To sum up: Originally Get/post way All is know, but note, ContentType and pass data match (this article data).

The students who have done the mock login and simulate the data submission must be very clear.



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.