这次给大家带来js跨域调用WebService的使用方法,js跨域调用WebService的注意事项有哪些,下面就是实战案例,一起来看一下。
步骤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
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:










