using System.Web.Script.Services;
[WebMethod]
public static List
GetArray()
{
List< ;string> li = new List();
for (int i = 0; i < 10; i )
li.Add(i "");
return li;
}
using System.Web.Script.Services;
[WebMethod]
public static List GetArray()
{
List li = new List();
for (int i = 0; i < 10; i )
li.Add(i "");
return li;
}
///
$(function() {
$("#btnOK").click( function() {
$.ajax({
type: "Post",
url: "data.aspx/GetArray",
contentType: "application/json; charset=utf-8" ,
dataType: "json",
success: function(data) {
//Clear ul before inserting
$("#list").html("");
("#list").append("< li>" this ""); error: function(err) {
alert(err); // /
$(function() {
$("#btnOK").click(function() {
$ .ajax({
type: "Post",
",
success: function(data) {
.append("< li>" this "");
});
alert(data.d); 🎜> });
Run result:
4. Return the call to the Hashtable method
asp.net code:
using System.Web.Script.Services;
using System.Collections;
[WebMethod]
public static Hashtable GetHash(string key,string value)
{
Hashtable hs = new Hashtable();
hs.Add("www", "yahooooooo");
hs.Add(key, value);
return hs;
}
using System.Web.Script.Services;
using System.Collections;
[WebMethod]
public static Hashtable GetHash(string key,string value)
{
Hashtable hs = new Hashtable();
hs.Add("www", "yahooooooo");
hs.Add(key, value);
return hs;
}
JQuery code:
///
$(function() {
$("#btnOK").click(function() {
$.ajax({
type: "Post",
url: "data.aspx/GetHash",
//Remember to add double quotes T_T
data: "{ 'key': 'haha', 'value': 'Haha ! ' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert("key: haha ==> " data.d["haha"] "n key: www ==> " data.d["www"]); > );
});
///
$(function() {
$("#btnOK").click(function() {
$.ajax({
type: "Post",
url: "data.aspx/GetHash",
//Remember to add double quotes T_T
data: "{ 'key ' : 'haha', 'value': 'Haha! ' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert("key: haha = alert("key: haha = => " data.d["haha"] "n key: www ==> " data.d["www"]);
},
error: function(err) {
alert(err "err");
}
});
运行结果:
5、操作xml
XMLtest.xml:
-
1
qwe
-
2
asd
1
qwe
2
asd
JQuery code:
$(function() {
$("#btnOK").click(function() {
$.ajax({
url: "XMLtest.xml",
dataType: 'xml', //The returned type is XML, which is different from the previous Json
success: function(xml) {
success: function(xml) {
//Clear the list
$("#list") .html("");
//Find xml elements KVM Online Shopping Brush Website Construction Beijing Express Company Ultrasonic Welding Machine
$(xml).find("data>item").each(function() $ ("#list").append("
Name:" $(this).find("name").text() ""); ,
error: function(result, status) { //If there is no above captured error, the callback function here will be executed >
//Disable button submission
return false;
});
});
$(function() {
$("#btnOK").click(function() {
; function(xml) {
. > item").each(function() {
li>");
})
},
error: function(result, status) { //If there is no capture error above, the callback function here will be executed
}
});