Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that jquery cannot receive data

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to solve the problem that jquery can not receive data". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to solve the problem that jquery can not receive data".

Jquery can not receive data solutions: 1, set "contentType:" application/x-www-form-urlencoded ""; 2, check post and get statements.

This article operating environment: Windows7 system, jquery3.2.1, Dell G3 computer.

Ajax post data cannot get the data. Pay attention to the setting of content-type and post/get.

About jQuery data passing data. All kinds of data can not be obtained on the Internet, garbled and so on.

Well, I also met today, check all kinds of entanglements on the Internet. No matter if you look at the garbled code, you can't get the data.

Because parameters have been passed in the way of jQuery ajax get before, the value of contentType has not been set by default.

1: var Skip = 49; / / Number of skipped row 2: var Take = 14; / / 3: function Load (Skip, Take) {4: ('# pPostsLoader') .html ('

); 5: / / send a query to server side to present new content 6: $.ajax ({7: type: "get", 8: url: "AjaxImage.ashx", 9: data: {Skip: Skip, Take: Take}, 10: / / contentType: "application/json Charset=utf-8 ", / / (OK) 11: / / contentType:" text/xml ", / / (OK) 12: / / contentType:" application/x-www-form-urlencoded ", / / (OK) 13: / / dataType:" string " 14: success: function (data) {15: if (data! = ") {16: $('.thumb') .append (data) 17:} 18: $('# pPostsLoader') .empty (); 19:} 20:}) 21:}

Under chrome, the value of contentType is not set. OK, let's take a look at the default in jquery:

The default parameter is passed through the url parameter, and the content type of the request is application/x-www-form-urlencoded.

General processing file to get parameter content:

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

No pressure, because that's what I do all the time, no problem. All right, let's change the type of content requested:

1: / / contentType: "application/json; charset=utf-8", / / (OK) 2: / / contentType: "text/xml", / / (OK)

Either is fine, and the parameters are obtained normally.

This is what we call get mode, and the parameters follow url, not Content-Type.

But today we are going to use post.

1: $.ajax ({2: type: "post"

Under chrome, the value of contentType is not set. Let's look at the default:

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

Well, by default, file acquisition parameters are also available by default.

However, but I started with contentType: "application/json; charset=utf-8". Look at the picture:

What is Request Paload?

Debug it and look inside our from. There is no content:

After testing:

1: / / contentType: "application/json; charset=utf-8", / / (not allowed) 2: / / contentType: "text/xml", / / (not allowed) 3: contentType: "application/x-www-form-urlencoded", / / (OK)

To sum up: get/post methods are known, but note that contentType matches the passed data (data in this article).

Students who have done simulated login and simulated submission of data must be very clear.

The above is all the contents of the article "how to solve the problem that jquery can not receive data". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report