A simple example of js cross-origin WebService calling. js cross-origin webservice

Source: Internet
Author: User

A simple example of js cross-origin WebService calling. js cross-origin webservice

Step 1.Add the following content to the system. web node in web. config:

<! -- This node allows scripts to call webservice across domains --> <webServices> <protocols> <add name = "HttpPost"/> <add name = "HttpGet"/> </protocols> </webServices> <! -- This node allows scripts to call webservice across domains -->

Step 2.Webservice code

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. services; using System. web. mvc; namespace WebService {// <summary> // abstract description of WebService1 /// </summary> [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream . [System. web. script. services. scriptService] public class WebService1: System. web. services. webService {[ValidateInput (false)] [WebMethod (Description = "test")] public void getDBTableInfos (string performanisecode) {HttpContext. current. response. contentType = "application/json; charset = UTF-8"; string jsonCallBackFunName = string. empty; jsonCallBackFunName = HttpContext. current. request. params ["jsoncallback"]. toString (); HttpContext. current. response. write (jsonCallBackFunName + "({\" Result \ ": \" "+ performanisecode + "\"})");}}}

Step 3.Html page

<! DOCTYPE html> 

The above is all the simple examples of js cross-origin WebService calling provided by xiaobian. I hope it will be helpful to you and support more customers ~

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.