Home > Web Front-end > JS Tutorial > body text

jQuery AJax calls asp.net webservers implementation code

高洛峰
Release: 2017-01-12 14:23:42
Original
867 people have browsed it

aspx page code

 
 
  
   
   
   

  
  
    

      jQuery 的WebServices 调用

    
      HelloWorld
    
      传入参数
    
      返回集合
    
      返回复合类型
    
      返回DataSet(XML)
  
  
    服务器处理中,请稍后。   
  
  
  
Copy after login

WebService1.asmx code

using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using System.Web.Services.Protocols; 
using System.Xml.Linq; 
using System.Collections.Generic; 
namespace jquery_Learning 
{ 
///  
/// 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 
{ 
///  
/// 无参数 
///  
///  
[WebMethod] 
public string HelloWorld() 
{ 
return "Hello World "; 
} 
///  
/// 带参数 
///  
///  
///  
///  
///  
///  
[WebMethod] 
public string GetWish(string value1, string value2, string value3, int value4) 
{ 
return string.Format("祝您在{3}年里 {0}、{1}、{2}", value1, value2, value3, value4); 
} 
///  
/// 返回集合 
///  
///  
///  
[WebMethod] 
public List GetArray(int i) 
{ 
List list = new List(); 
while (i >= 0) 
{ 
list.Add(i--); 
} 
return list; 
} 
///  
/// 返回一个复合类型 
///  
///  
[WebMethod] 
public Class1 GetClass() 
{ 
return new Class1 { ID = "1", Value = "牛年大吉" }; 
} 
///  
/// 返回XML 
///  
///  
[WebMethod] 
public DataSet GetDataSet() 
{ 
DataSet ds = new DataSet(); 
DataTable dt = new DataTable(); 
dt.Columns.Add("ID", Type.GetType("System.String")); 
dt.Columns.Add("Value", Type.GetType("System.String")); 
DataRow dr = dt.NewRow(); 
dr["ID"] = "1"; 
dr["Value"] = "新年快乐"; 
dt.Rows.Add(dr); 
dr = dt.NewRow(); 
dr["ID"] = "2"; 
dr["Value"] = "万事如意"; 
dt.Rows.Add(dr); 
ds.Tables.Add(dt); 
return ds; 
} 
} 
//自定义的类,只有两个属性 
public class Class1 
{ 
public string ID { get; set; } 
public string Value { get; set; } 
} 
}
Copy after login

For more jQuery AJax implementation code for calling asp.net webservers related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!