JQuery $.post () Why and how to return a callback function when the type is JSON

Source: Internet
Author: User

This is really a special scratching the heart to find the problem of liver, really almost by this problem forced to give up to use JSON as the return type, but to use HTML, but sometimes it is more juice. (Even if the problem is solved now, I would like to say "Mama egg", to vent a bit)

In fact, the main or self-sufficient understanding of the JSON, but very puzzled, on-line approach to the solution is almost no. So although the problem is very small, but still want to share, hoping to help the people who need.

The first $.post () format is as follows:

$.post (url,data,success (data, Textstatus, JQXHR), DataType)

Parameter description

URL
Necessary. Specifies which URL to send the request to.

Data
Optional. The map or string value. Basic is JSON format.

success (data, Textstatus, JQXHR)
Optional. The callback function to execute when the request succeeds.

DataType

Optional. Specifies the data type of the expected server response. The default is to perform smart judgments (XML, JSON, script, or HTML).

Example:

                $.post (".. /.. /xxx/ajaxpost.aspx ",                     {                         action:  "XXX",                          id: xxx                     },function  (Data,status)  {                          Alert ("Name=" +data.name+ ", age=" +data.age);                     },     "JSON"); 

Break points can be entered into the background normally. Until the desired operation is complete, the new JSON data is composed, the Response.Write () is returned, but the function () method is not used in any way, but it is not possible to change the JSON format.

Then finally finally

Background:

result = "{\" name\ ": \" Michael jordan\ ", \" age\ ": \" 51\ "}";            Response.Write (Result); Response.End ();

Notice that the JSON format is {"Key1": "Value1", "Key2": "Value2"} (or double quotes in {} into single quotes), but in the C # code part it needs to be preceded by the escape character (\) in quotation marks (""). Otherwise, you will never get to the callback method.

The $.post () method is strictly required to use the JSON format to enter callbacks when JSON is used as the return type. So......

Run:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/A7/wKiom1QX7aPzY_pEAABX7owqAEY157.jpg "title=" Qq20140916152921.jpg "alt=" Wkiom1qx7apzy_peaabx7owqaey157.jpg "/>

This article is from the "Give Me a Gener cigarette" blog, please be sure to keep this source http://zhouhongyu1989.blog.51cto.com/2931598/1553324

JQuery $.post () Why and how to return a callback function when the type is JSON

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.