How js calls WebService across domains
This article is about how js calls WebService across domains. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Step 1. Add to the system.web node in web.config
Step 2. Webservice code
Using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Mvc Summary description of namespace WebService {/ WebService1 / [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem (false)] / / to allow this Web service to be called from a script using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WebService1: System.Web.Services.WebService {[ValidateInput (false)] [WebMethod (Description = "test")] public void getDBTableInfos (string EnterpriseCode) {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\ ":\" + EnterpriseCode + "\"}));}
Step 3. Html page section
Index $(function () {$("# btnSubmit") .click (function () {var EnterpriseCode= "39"; / / Enterprise Code var dataStr = "EnterpriseCode=" + EnterpriseCode) $.ajax ({type: "get", url: "http://xxx/xxx.asmx/AntiWebQuery_Ajax?jsoncallback?", dataType:" jsonp ", jsonp: 'jsoncallback', data: dataStr, success: function (result) {/ / return result alert (result.Result);}}) Thank you for reading! This is the end of the article on "how js calls WebService across domains". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!