Ajax post data does not get the information

Source: Internet
Author: User

Ajax post data is not available, note the settings of Content-type, Post/get
About JQuery data. Online all kinds of access to data, garbled and so on.
Well, I also met today, on the Internet to find a variety of entanglements. Garbled no matter what the first look to get data.
Because the parameters have been passed in jquery Ajax get before, the value of ContentType is not set by default.

1      varSkip = the;//Number of skipped row2      varTake = -;//3 function Load (Skip, take) {4$('#divPostsLoader'). HTML ('');5          //send a query to server side to present new content6 $.ajax ({7Type"Get",8Url:"ajaximage.ashx",9 data: {skip:skip, take:take},Ten               //contentType: "Application/json; Charset=utf-8 ",//(yes) One              //contentType: "Text/xml",//(yes) A               //contentType: "application/x-www-form-urlencoded",//(yes) -              //dataType: "string", - success:function (data) { the                   if(Data! ="") { -$('. Thumb'). append (data); -                   } -$('#divPostsLoader'). empty (); +               } -           }) +};
View Code



Chrome, without setting the value of ContentType, OK, let's see by default:



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

General processing files get parameter contents:

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

There is no pressure, because I have been so dry laughing, there is no problem. All right, let's change it. The requested content type:
ContentType: "Application/json; Charset=utf-8 ",//(CAN) 2://contenttype:" Text/xml ",//(CAN)


can also be, parameters get normal.
This is what we call the Get method, the parameters are followed by the URL, not related to Content-type.



But today we have to use the Post method has wood.

$.ajax ({2:type: "POST",
Chrome does not set the value of contenttype to see the default:



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

Well, by default, it is also possible to handle the file acquisition parameters generally.

But the first thing I set was contentType: "Application/json; Charset=utf-8 ", look at the picture:



What is the Request paload???

Debug, look at our from inside, no content:



Well, by the way, we solved the problem in Bo's question (http://q.cnblogs.com/q/11342/),

Originally search this Bo asked, very happy, but, there is no wood, small partners are not kind Ah! Laugh

Tested By:

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



To summarize: The original Get/post way is known, but note that the contenttype and pass data matching (this document).

The students who have done the simulation login and submit data are sure to be clear.

Ajax post data does not get the information

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.