页面代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="jquery-1.7.2.js"></script>
<script type="text/javascript">
onload=function(){
//web service的调用
$.ajax({
type: "get",
contentType: 'application/json',
url: "http:www.LCWeb.com/WebService.cs/HelloWorld",
dataType: "xml",
success: function (data) {
alert(data);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="div1">
</div>
</form>
</body>
</html>

Web Service中的代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services; /// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://microsoft.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{ public WebService()
{ //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public List<Student> HelloWorld()
{
//编写连接字符串
string conStr = "Data Source=.;Initial Catalog=school;Integrated Security=True";
//创建连接对象
SqlConnection conn = new SqlConnection(conStr);
//编写sql语句
string sqlStr = "select * from student";
//创建适配器对象
SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, conn);
//创建临时表对象
DataTable dt = new DataTable();
//填充表数据
adapter.Fill(dt);
List<Student> stuList = new List<Student>();
//将数据封装成集合
for (int i = 0; i < dt.Rows.Count; i++)
{
stuList.Add(new Student
{
Id = Convert.ToInt32(dt.Rows[i]["id"].ToString()),
Name = dt.Rows[i]["Name"].ToString(),
});
}
return stuList;
} }

实体类中的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// Student 的摘要说明
/// </summary>
public class Student
{
public Student()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public int Id { get; set; }
public String UserName { get; set; }
public String Pwd { get; set; }
public string Name { get; set; }
}

ajax调用webService中的方法的更多相关文章

  1. 【转】利用ScriptManager实现Javascript调用WebService中的方法

    原文发布时间为:2009-07-01 -- 来源于本人的百度文章 [由搬家工具导入] 前台调用后台方法,或者后台调用前台方法。ScriptManager实现 开发过程中,总想在前台直接调用后台的met ...

  2. ajax 调用asp.net后台方法

    ajax 调用asp.net后台方法  这种做法有好几种,如调用xx.asxh 页面,或者直接调用xx.aspx也面,在page_Load中进行一些判断然后调用后面的其他方法, 或者你可以直接调用we ...

  3. Ajax调用WebService(一)

    Ajax调用WebService(一) http://www.cnblogs.com/leslies2/archive/2011/01/26/1934889.html 分类: Ajax 使用技术 We ...

  4. ASP.NET实现二维码 ASP.Net上传文件 SQL基础语法 C# 动态创建数据库三(MySQL) Net Core 实现谷歌翻译ApI 免费版 C#发布和调试WebService ajax调用WebService实现数据库操作 C# 实体类转json数据过滤掉字段为null的字段

    ASP.NET实现二维码 using System;using System.Collections.Generic;using System.Drawing;using System.Linq;us ...

  5. Ajax调用WebService接口样例

    在做手机端h5的应用时,通过Ajax调用http接口时没啥问题的:但有些老的接口是用WebService实现的,也来不及改成http的方式,这时通过Ajax调用会有些麻烦,在此记录具体实现过程.本文使 ...

  6. Jquery ajax调用webservice总结

    jquery ajax调用webservice(C#)要注意的几个事项: 1.web.config里需要配置2个地方 <httpHandlers>      <remove verb ...

  7. java 调用webservice的各种方法总结

    java 调用webservice的各种方法总结 几种流行的开源WebService框架Axis1,Axis2,Xfire,CXF,JWS比较 方法一:创建基于JAX-WS的webservice(包括 ...

  8. Ajax调用WebService

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...

  9. Jquery Ajax 调用 WebService

    原文:http://www.cnblogs.com/andiki/archive/2010/05/17/1737254.html jquery ajax调用webservice(C#)要注意的几个事项 ...

随机推荐

  1. Android UI设计系统---LayoutParams[转]

    LayoutParams继承于Android.View.ViewGroup.LayoutParams.       LayoutParams相当于一个Layout的信息包,它封装了Layout的位置. ...

  2. Java [leetcode 35]Search Insert Position

    题目描述: Given a sorted array and a target value, return the index if the target is found. If not, retu ...

  3. Struts2 教程

    一.Struts2是什么 Struts2是在WebWork2基础发展而来的.和Struts1一样, Struts2也是基于MVC的web层框架. 那么既然有了Struts1,为何还要Struts2? ...

  4. ZOJ 2283 Challenge of Wisdom

    题意:在一个n * m的地图里,有p个宝藏,每次只能向横纵坐标增加的方向走,问最少走几次能把宝藏都拿走. 解法:按横坐标排序,纵坐标的一个不下降子序列就是一条合法路径,要求多少条不下降子序列可以覆盖所 ...

  5. [Everyday Mathematics]20150102

    设 \[ a_1=3,\quad a_{n+1}=\dfrac{1}{2}(a_n^2+1)\quad(n=1,2,\cdots). \] 试求 \[ \vsm{n}\dfrac{1}{1+a_n}. ...

  6. HDU 5623KK's Number DP

    题意:bc round 71 div 1 1003(有中文题面) 分析: 显然,每个人的策略就是都会拿剩下的数中最大的某几个数 假如我们用dp[i]表示当剩下i个数的时候先手得分-后手得分的最优值 那 ...

  7. Java + Excel 接口自动化

    最近项目比较悠闲,想找点事干,写了个 Excel 接口测试的 "框架" 以前用 python 写过一个,这次用 java, 应该说框架都不算,反正就是写了,能帮我解决问题就行. 当 ...

  8. 位图9宫格 BitmapSlice9.jsfl

    /** * Version 1.1, May 4: fixed issue with symbols in library folders. **/ /** * BitmapSlice9 JSFL b ...

  9. const,readonly,static

    1.const 表示的是常量(constant),始终不会发生改变,在编译时就确定了.所以类中定义一个常量可以被类访问也可以被类的实例访问.定义时就不能和static一起用.如果用了也是没有作用的,所 ...

  10. mapreduce学习指导及疑难解惑汇总

    原文链接http://www.aboutyun.com/thread-7091-1-1.html 1.思想起源: 我们在学习mapreduce,首先我们从思想上来认识.其实任何的奇思妙想,抽象的,好的 ...