您现在的位置是:网站首页> 编程资料编程资料
js跨域调用WebService的简单实例_AJAX相关_
2023-05-25
316人已围观
简介 js跨域调用WebService的简单实例_AJAX相关_
步骤1. 在web.config中的system.web节点里加入
步骤2. webservice代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Mvc; namespace WebService { /// /// WebService1 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [ValidateInput(false)] [WebMethod(Description = "测试")] 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 + "\" })"); } } } 步骤3. html页面部分
Index
以上就是小编为大家带来的js跨域调用WebService的简单实例的全部内容了,希望对大家有所帮助,多多支持~
您可能感兴趣的文章:
相关内容
- Ajax实现带有验证码的局部刷新登录界面_AJAX相关_
- 细数Ajax请求中的async:false和async:true的差异_AJAX相关_
- ajax无刷新评论功能_AJAX相关_
- 使用ajax实现分页技术_AJAX相关_
- Ajax入门学习教程(一)_AJAX相关_
- Ajax和$.ajax使用实例详解(推荐)_AJAX相关_
- Ajax实现注册并选择头像后上传功能_AJAX相关_
- Ajax 设置Access-Control-Allow-Origin实现跨域访问_AJAX相关_
- Ajax跨域访问Cookie丢失问题的解决方法_AJAX相关_
- Ajax动态为下拉列表添加数据的实现方法_AJAX相关_
