您的位置:首页 > Web前端 > JQuery

C# 利用JQuery调用后台方法

2012-12-14 17:28 387 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JQueryTest.aspx.cs" Inherits="MsChartTest.JQueryTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title></title>

<mce:script src="JS/jquery.js" mce_src="JS/jquery.js" type="text/javascript"></mce:script>

<mce:script type="text/javascript"><!--

$(function() {

$("#btnOK").click(function() {

$.ajax({

type: "Post",

url: "JQueryTest.aspx/SayHello",

data: "{}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(data) {

alert(data.d);

},

error: function(err) {

alert(err);

}

});

return false;

});

$("#btnOK0").click(function() {

$.ajax({

type: "Post",

url: "JQueryTest.aspx/GetStr",

data: "{'str':'我是','str2':'XXX'}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(data) {

alert(data.d);

},

error: function(err) {

alert(err);

}

});

return false;

});

$("#btnOK1").click(function() {

$.ajax({

type: "Post",

url: "JQueryTest.aspx/GetArray",

data: "{}",

contentType: "application/json; chartset=utf-8",

dataType: "json",

success: function(data) {

$("#list").html("");

$(data.d).each(function() {

$("#list").append("<li>" + this + "</li>");

});

alert(data.d);

},

error: function(err) {

alert(err);

}

});

return false;

});

$("#btnOK2").click(function() {

$.ajax({

type: "Post",

url: "JQueryTest.aspx/GetHash",

data: "{'key':'haha','value':'哈哈!'}",

contentType: "application/json: charset=utf-8",

dataType: "json",

success: function(data) {

alert("key:haha==>" + data.d["haha"] + "/n key:www==>" + data.d["www"]);

},

error: function(err) {

alert(err + "err");

}

});

return false;

});

$("#btnOK3").click(function() {

$.ajax({

url: "XMLTest.xml",

dataType: 'xml',

success: function(xml) {

$("#list1").html("");

$(xml).find("data>item").each(function() {

$("#list1").append("<li>id:" + $(this).find("id").text() + "</li>");

$("#list1").append("<li>name:" + $(this).find("name").text() + "</li>");

})

},

error: function(result, status) {

alert(status);

}

});

return false;

});

});

// --></mce:script>

</head>

<body>

<form id="form1" runat="server">

<div>

<input id="btnOK" type="button" value="button" />

<input id="btnOK0" type="button" value="button" />

<input id="btnOK1" type="button" value="button" />

<input id="btnOK2" type="button" value="button" />

<input id="btnOK3" type="button" value="button" />

<ul id="list"></ul>

<ul id="list1"></ul>

</div>

</form>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: