The mysteries of jQuery ajax get and post background Interaction

Source: Internet
Author: User

These two days, I am working on the follow function module (similar to Instagram ). For multiple pages, you must follow or cancel a friend by clicking the "follow" button. Put a button corresponding to a page for operation. Low Efficiency and poor maintainability. Therefore, to use jQuery's ajax Method for asynchronous operations, the efficiency is high, the effect is fast, and it is encapsulated, you only need to reference a few JS files, you can easily use. Therefore, we first thought about using the get method.

First, reference the jQuery class library file and json2.js (reliable furniture, mainly used to convert the strings returned to the front-end to JSON objects. FF does not need to reference this file, mainly in IE, because IE does not support the JSON. parse method ).

<! -- [If IE]> <script type = "text/javascript" src = "json2.js"> </script> <! [Endif] --> This annotation can only be recognized by IE to reference json2.js in IE, but not in other browsers.

Follow the code below to implement the function. The specific problem will be analyzed later.

JQuery get and post [note]

The JSON code () returned by the background call is as follows ():

  Page_Load(            Response.Write(

If you use $. you will find that every time you click the "follow" link, the correct pop-up dialog box will prompt us for feedback in the background, but don't be blinded by this illusion. It's just the beginning of the "get" method, when you perform breakpoint tracking in the background, we will find that $. in the get method, When you click the link for the first time, the breakpoint will go to the background, but when you click more than once, it will never jump to the background, however, we always use the illusion to prompt the dialog box, which makes us mistakenly think that we have already interacted with the background.

The problem I encountered at the beginning was that the front-end prompted me to follow the operation successfully, but the fields in the database were not modified (except for the first operation ). until I set $. replace the get method with $. the post method solves the problem.

I checked the information and found

I hope you will be able to pay attention to the usage of $. get and $. post to avoid wasting a lot of unnecessary time... learning through continuous summarization, and the effect is the best.

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.