ajax调用webService中的方法
页面代码
<%@ 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中的方法的更多相关文章
- 【转】利用ScriptManager实现Javascript调用WebService中的方法
原文发布时间为:2009-07-01 -- 来源于本人的百度文章 [由搬家工具导入] 前台调用后台方法,或者后台调用前台方法。ScriptManager实现 开发过程中,总想在前台直接调用后台的met ...
- ajax 调用asp.net后台方法
ajax 调用asp.net后台方法 这种做法有好几种,如调用xx.asxh 页面,或者直接调用xx.aspx也面,在page_Load中进行一些判断然后调用后面的其他方法, 或者你可以直接调用we ...
- Ajax调用WebService(一)
Ajax调用WebService(一) http://www.cnblogs.com/leslies2/archive/2011/01/26/1934889.html 分类: Ajax 使用技术 We ...
- 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 ...
- Ajax调用WebService接口样例
在做手机端h5的应用时,通过Ajax调用http接口时没啥问题的:但有些老的接口是用WebService实现的,也来不及改成http的方式,这时通过Ajax调用会有些麻烦,在此记录具体实现过程.本文使 ...
- Jquery ajax调用webservice总结
jquery ajax调用webservice(C#)要注意的几个事项: 1.web.config里需要配置2个地方 <httpHandlers> <remove verb ...
- java 调用webservice的各种方法总结
java 调用webservice的各种方法总结 几种流行的开源WebService框架Axis1,Axis2,Xfire,CXF,JWS比较 方法一:创建基于JAX-WS的webservice(包括 ...
- Ajax调用WebService
前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...
- Jquery Ajax 调用 WebService
原文:http://www.cnblogs.com/andiki/archive/2010/05/17/1737254.html jquery ajax调用webservice(C#)要注意的几个事项 ...
随机推荐
- 银行卡luhm校验算法
/** * 15位银行卡luhm校验算法 * 1.从卡号最后一位数字开始,逆向将奇数位(1.3.5等等)相加. * 2.从卡号最后一位数字开始,逆向将偶数位数字,先乘以2(如果乘积为两位数,则将其减去 ...
- MenuInflater用法
MenuInflater是用来加载menu布局文件的. 与LayoutInflater类似,应用程序运行时会预先加载资源中的布局文件,如果Menu布局中的资源比较多,会影响性能,所以可以选择MenuI ...
- [转]ASP.NET MVC Jquery Validate 表单验证的多种方式介绍
在我们日常开发过程中,前端的表单验证很重要,如果这块处理不当,会出现很多bug .但是如果处理的好,不仅bug会很少,用户体验也会得到很大的提升.在开发过程中我们可以不借助 JS 库,自己去手写 JS ...
- mina2
远程通信 Mina2 学习笔记 作者:李少华 邮箱:xiaosanshaoli@126.com QQ:305409913 2010-12-23 初稿 引言... 1 一. Mina ...
- Android中Bitmap和Drawable,等相关内容
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- 27、Service
1服务可以通过startservice的方法 开启.通过stopservice的方法 停止. 服务有一个特点: 只会一次onCreate()方法一旦被创建出来,以后oncreate() 就不会再被执行 ...
- 介绍并扩展Fitnesse的测试模块化机制:ScenarioTable
摘要:在验收测试框架Fitneese中,使用Scenario可以把最常用的测试步骤封装起来,从而达到模块化定义Fitnesse测试用例的能力.但Scenario仅限于封装Script测试步骤,Scri ...
- 设计模式_Interpreter_解释器模式
形象例子: 俺有一个<泡MM真经>,上面有各种泡MM的攻略,比如说去吃西餐的步骤.去看电影的方法等等,跟MM约会时,只要做一个Interpreter,照着上面的脚本执行就可以了.解释器模式 ...
- git ssh key for github
第一:检查.ssh是否存在(ls -al ~/.ssh) $ ls -al ~/.ssh Lists the files in your .ssh directory, if they exist 第 ...
- jQuery遍历多层json数据
1.json与jsonp的区别(待查) 2.要遍历的数据如下: {"status": "ok", "code": 200, "da ...