zoukankan
html css js c++ java
Basic of Ajax
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
CallWebService.aspx.cs
"
Inherits
=
"
CallWebService
"
%>
<!
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
>
Untitled Page
</
title
>
</
head
>
<
body
>
<
script
language
="javascript"
>
var
xmlhttp
=
false
;
try
{
xmlhttp
=
new
ActiveXObject(
"
Msxml2.XMLHTTP
"
);
}
catch
(e)
{
try
{
xmlhttp
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
}
catch
(e)
{
xmlhttp
=
false
;
}
}
if
(
!
xmlhttp
&&
typeof
xmlhttp
!=
'
undefined
'
)
{
try
{
xmlhttp
=
new
XMLHttpRequest();
}
catch
(e)
{
xmlhttp
=
false
;
}
}
function
RequestByGet()
{
//
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//
to call webservice
var
URL
=
"
http://localhost/webservicetest/service.asmx/GetDataSet?name=
"
+
document.getElementById(
"
txt
"
).value;
xmlhttp.Open(
"
GET
"
,URL,
true
);
xmlhttp.onreadystatechange
=
updatePage;
xmlhttp.Send(
null
);
//
var result = xmlhttp.status;
//
if(result == 200)
//
document.write(xmlhttp.responseText);
//
xmlhttp = null;
}
function
RequestByPost()
{
var
strPara
=
"
name=
"
+
document.getElementById(
"
txt
"
).value;
//
to call general .aspx file
var
URL
=
"
BeCalled.aspx
"
;
xmlhttp.Open(
"
POST
"
,URL,
false
);
xmlhttp.SetRequestHeader(
"
Content-Type
"
,
"
application/x-www-form-urlencoded
"
);
xmlhttp.SetRequestHeader(
"
Content-Length
"
,strPara.length);
xmlhttp.Send(strPara);
var
result
=
xmlhttp.status;
if
(result
==
200
)
document.write(xmlhttp.responseText);
else
alert(result);
xmlhttp
=
null
;
}
function
updatePage()
{
if
(xmlhttp.readyState
==
4
)
{
document.getElementById(
"
showstatus
"
).innerText
=
""
;
if
(xmlhttp.status
==
200
)
{
//
alert(xmlhttp.responseXML.xml);
document.getElementById(
"
age
"
).value
=
xmlhttp.responseXML.selectSingleNode(
"
//diffgr:diffgram/NewDataSet/Table1/b
"
).text;
}
else
if
(xmlhttp.status
==
404
)
alert(
"
Requested URL is not found.
"
);
else
if
(xmlhttp.status
==
403
)
alert(
"
Access denied.
"
);
else
alert(
"
error, status code:
"
+
xmlhttp.status);
}
else
document.getElementById(
"
showstatus
"
).innerText
=
"
loading
"
;
}
</
script
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
div
id
="showstatus"
></
div
>
<
input
type
="text"
id
="txt"
onchange
="RequestByGet()"
/>
<!--
<input type="button" value="CallWebServiceByGet" onclick="RequestByGet()" />
-->
<
input
type
="button"
value
="CallWebServiceByPost"
onclick
="RequestByPost()"
/>
<
br
/>
<
input
type
="text"
id
="age"
/>
</
div
>
</
form
>
</
body
>
</
html
>
查看全文
相关阅读:
最大最小值得判断代码
等腰三角形的代码及各类代码
Java ArrayList和Vector、LinkedList与ArrayList、数组(Array)和列表集合(ArrayList)的区别
Java 集合类的特性
Java 用程序给出随便大小的10 个数,序号为1-10,按从小到大顺序输出,并输出相应的序号?
List、Map、Set三个接口,存取元素时,各有什么特点?
Java 清除数组相同元素
eclipse导入项目出现叹号处理方法:
初学者-PHP笔记
java 对象输入输出流
原文地址:https://www.cnblogs.com/silva/p/1044638.html
最新文章
javadoc
IntelliJ IDEA License Server
AndroidStudio开发环境配置-Windows
深入.NET平台和C#编程
实现Windows程序的数据更新
使用C#开发数据库应用系统
使用C#开发数据库应用系统
初识windows程序
使用ADO.NET查询和操作数据2
使用ADO.NET访问数据库
热门文章
连接查询和分组查询
模糊查询和聚合查询
IDER软件安装破解,以及初始的数据展示
s1--(1)--五 预习
s1--(1)--四 预习
4.18作业合集
s1--(1)--三 预习
s1--(1)--二 预习
S1--(1) 一.预习
10章作业(全)
Copyright © 2011-2022 走看看