Notes for Calling C # background methods using jquery

Source: Internet
Author: User

Jquery can directly call the PAGE method, but every time it is used, it is always a wave of twists and turns. The following are the precautions during use.

1. In vs2008, it seems that the page background page cannot be called directly. It is said that the configuration file must be modified.

2. To call the page background method, you must first reference the namespace using system. Web. Services. Then the method must be a static method, and the method must be marked as [webmethod].

 

 

3. jquery calls at the front end as follows:

$. Ajax ({

Type: "Post ",
Contenttype: "application/JSON ",
URL: "/admin/sysmanage/adminmenuadd. aspx/addadminmenu ",
Data: "{menuname: '" + menuname + "', parentmenu: '" + parentmenu + "', menupath: '" + menupath + "', sortnum: '"+ sortnum +"', status: '"+ status + "'}",
Datatype: 'json ',
Success: Function (E ){
Alert (E. D );
}

})

 

 

There are several important parameter types:

1. unlike jquery's call to ashx, the parameter data must be written in double quotation marks, for example, data: "{parm1: '" + parmvalue + "'}". Data: {parm1: parmvalue}

2.Contenttype: "application/JSON ",Type must be specified for this item
 3. Why does alert write like this? "E. D"

The returned result is of the JSON type. The format is {"D": 1}

You can see in httpwatch

 

 

 

 

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.