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
>
查看全文
相关阅读:
10月15日模拟赛题解
NOIp初赛题目整理
【meet in the mid】【qbxt2019csp刷题班day1C】birthday
【字符串】 manacher算法
【border树】【P2375】动物园
【border相关】【P3426】 [POI2005]SZA-Template
【字符串】 Z-algorithm
【字符串】KMP
【神奇性质】【P5523】D [yLOI2019] 珍珠
【线段树】【P5522】[yLOI2019] 棠梨煎雪
原文地址:https://www.cnblogs.com/silva/p/1044638.html
最新文章
最小圆覆盖
Beauty Contest(旋转卡壳模版题)
Feng Shui
To-do List
csp-s 2019 游记
省略的缺省源
咕咕咕
SDOI2019Round1游记
那些古风
【P6307】选择客栈 加强版
热门文章
【数论】乘法逆元
多项式操作公式记录
【多项式】FFT
【字符串】【P5830】 【模板】失配树
【可持久化线段树】【P5826】【模板】子序列自动机
【DP】【P5615】 [MtOI2019] 时间跳跃
【贪心】【P4053】[JSOI2007] 建筑抢修
10月28日模拟赛题解
【字符串】后缀排序
10月20日模拟赛题解
Copyright © 2011-2022 走看看