Jquery Ajax WebService
来源:互联网 发布:淘宝宝贝收藏有什么用 编辑:程序博客网 时间:2024/05/20 01:34
仅供参考ws.aspx 代码
$.ajax({
type: "POST", //访问WebService使用Post方式请求
contentType: "application/json",//WebService 会返回Json类型
url: "WebService1.asmx/HelloWorld",//调用WebService的地址和方法名称组合 ---- WsURL/方法名
data: "{}", //这里是要传递的参数,格式为 data: "{paraName:paraValue}",下面将会看到
dataType: 'json',
success: function(result) { //回调函数,result,返回值
$('#dictionary').append(result.d);
}
});
//有参数调用
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService1.asmx/GetWish",
data: "{value1:'心想事成',value2:'万事如意',value3:'牛牛牛',value4:2009}",
dataType: 'json',
success: function(result) {
$('#dictionary').append(result.d);
}
});
//返回集合(引用自网络,很说明问题)
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService1.asmx/GetArray",
data: "{i:10}",
dataType: 'json',
success: function(result) {
$(result.d).each(function() {
//alert(this);
$('#dictionary').append(this.toString() +" ");
//alert(result.d.join(" | "));
});
}
});
//返回复合类型
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService1.asmx/GetClass",
data: "{}",
dataType: 'json',
success: function(result) {
$(result.d).each(function() {
//alert(this);
$('#dictionary').append(this['ID'] +" " + this['Value']);
//alert(result.d.join(" | "));
});
}
});
//返回DataSet(XML)
$.ajax({
type: "POST",
url: "WebService1.asmx/GetDataSet",
data: "{}",
dataType: 'xml', //返回的类型为XML ,和前面的Json,不一样了
success: function(result) {
//演示一下捕获
try {
$(result).find("Table1").each(function() {
$('#dictionary').append($(this).find("ID").text() +" " + $(this).find("Value").text());
});
}
catch (e) {
alert(e);
return;
}
},
error: function(result, status) {//如果没有上面的捕获出错会执行这里的回调函数
if (status == 'error') {
alert(status);
}
}
});
//Ajax 为用户提供反馈,利用ajaxStart和ajaxStop 方法,演示ajax跟踪相关事件的回调,他们两个方法可以添加给jQuery对象在Ajax前后回调
//但对与Ajax的监控,本身是全局性的
$(document).ready(function() {
$('#loading').ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
});
// 鼠标移入移出效果,多个元素的时候,可以使用“,”隔开
$(document).ready(function() {
$('div.button').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
});
[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
{
/// <summary>
/// 无参数
/// </summary>
/// <returns></returns>
[WebMethod]
public string HelloWorld()
{
return "Hello World ";
}
/// <summary>
/// 带参数
/// </summary>
/// <param name="value1"></param>
/// <param name="value2"></param>
/// <param name="value3"></param>
/// <param name="value4"></param>
/// <returns></returns>
[WebMethod]
public string GetWish(stringvalue1, string value2, string value3, int value4)
{
return string.Format("祝您在{3}年里 {0}、{1}、{2}", value1, value2, value3, value4);
}
/// <summary>
/// 返回集合
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
[WebMethod]
public List<int> GetArray(inti)
{
List<int> list =new List<int>();
while (i >= 0)
{
list.Add(i--);
}
return list;
}
/// <summary>
/// 返回一个复合类型
/// </summary>
/// <returns></returns>
[WebMethod]
public Class1GetClass()
{
return new Class1{ ID = "1", Value = "牛年大吉" };
}
/// <summary>
/// 返回XML
/// </summary>
/// <returns></returns>
[WebMethod]
public DataSetGetDataSet()
{
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; }
}
}
$.ajax({
type: "POST", //访问WebService使用Post方式请求
contentType: "application/json",//WebService 会返回Json类型
url: "WebService1.asmx/HelloWorld",//调用WebService的地址和方法名称组合 ---- WsURL/方法名
data: "{}", //这里是要传递的参数,格式为 data: "{paraName:paraValue}",下面将会看到
dataType: 'json',
success: function(result) { //回调函数,result,返回值
$('#dictionary').append(result.d);
}
});
//有参数调用
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService1.asmx/GetWish",
data: "{value1:'心想事成',value2:'万事如意',value3:'牛牛牛',value4:2009}",
dataType: 'json',
success: function(result) {
$('#dictionary').append(result.d);
}
});
//返回集合(引用自网络,很说明问题)
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService1.asmx/GetArray",
data: "{i:10}",
dataType: 'json',
success: function(result) {
$(result.d).each(function() {
//alert(this);
$('#dictionary').append(this.toString() +" ");
//alert(result.d.join(" | "));
});
}
});
//返回复合类型
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService1.asmx/GetClass",
data: "{}",
dataType: 'json',
success: function(result) {
$(result.d).each(function() {
//alert(this);
$('#dictionary').append(this['ID'] +" " + this['Value']);
//alert(result.d.join(" | "));
});
}
});
//返回DataSet(XML)
$.ajax({
type: "POST",
url: "WebService1.asmx/GetDataSet",
data: "{}",
dataType: 'xml', //返回的类型为XML ,和前面的Json,不一样了
success: function(result) {
//演示一下捕获
try {
$(result).find("Table1").each(function() {
$('#dictionary').append($(this).find("ID").text() +" " + $(this).find("Value").text());
});
}
catch (e) {
alert(e);
return;
}
},
error: function(result, status) {//如果没有上面的捕获出错会执行这里的回调函数
if (status == 'error') {
alert(status);
}
}
});
//Ajax 为用户提供反馈,利用ajaxStart和ajaxStop 方法,演示ajax跟踪相关事件的回调,他们两个方法可以添加给jQuery对象在Ajax前后回调
//但对与Ajax的监控,本身是全局性的
$(document).ready(function() {
$('#loading').ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
});
// 鼠标移入移出效果,多个元素的时候,可以使用“,”隔开
$(document).ready(function() {
$('div.button').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
});
[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
{
/// <summary>
/// 无参数
/// </summary>
/// <returns></returns>
[WebMethod]
public string HelloWorld()
{
return "Hello World ";
}
/// <summary>
/// 带参数
/// </summary>
/// <param name="value1"></param>
/// <param name="value2"></param>
/// <param name="value3"></param>
/// <param name="value4"></param>
/// <returns></returns>
[WebMethod]
public string GetWish(stringvalue1, string value2, string value3, int value4)
{
return string.Format("祝您在{3}年里 {0}、{1}、{2}", value1, value2, value3, value4);
}
/// <summary>
/// 返回集合
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
[WebMethod]
public List<int> GetArray(inti)
{
List<int> list =new List<int>();
while (i >= 0)
{
list.Add(i--);
}
return list;
}
/// <summary>
/// 返回一个复合类型
/// </summary>
/// <returns></returns>
[WebMethod]
public Class1GetClass()
{
return new Class1{ ID = "1", Value = "牛年大吉" };
}
/// <summary>
/// 返回XML
/// </summary>
/// <returns></returns>
[WebMethod]
public DataSetGetDataSet()
{
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; }
}
}
- ajax jquery webservice
- jquery ajax webservice ???
- jquery ajax webservice
- Jquery Ajax WebService
- Jquery Ajax WebService
- jquery ajax 调用WebService
- Jquery Ajax WebService
- ajax、jquery调用webservice
- Ajax,Jquery请求WebService
- webService学习9:jquery ajax调用webservice
- jQuery Ajax 调用 WebService 实例
- JQuery Ajax WebService传递参数
- Jquery ajax调用webservice总结
- Jquery Ajax方式访问WebService
- Jquery ajax调用webservice总结
- Jquery ajax调用webservice总结
- jquery用ajax调用webservice
- Jquery采用ajax调取WebService显示表格
- 纪念曼德拉
- test5-2(成绩处理)
- Higher Math
- PLSQL中显式Cursor、隐式Cursor、动态Ref Cursor
- 【九度】题目1017:还是畅通工程
- Jquery Ajax WebService
- Android 解析 Json 数据
- virtual box安装ubuntu64虚拟机。。。
- C语言十进制转二进制
- 转义字符和格式控制符
- 除3问题
- Android实现推送方式解决方案
- 你在云端需要怎样的安全功能?这是控制问题
- Linux下/etc/resolv.conf 配置DNS客户