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
>
查看全文
相关阅读:
用MobaXterm_Personal_12.0远程连接ubuntu虚拟机,并解决报错connection refused
二叉树图解以及二叉树的递归原理
Source Insight 4.0 安装使用简单粗暴教程
VScode配置嵌入式linux开发环境,代替source insight
linux系统下部署DNS正向解析
【剑指Offer】面试题47. 礼物的最大价值
【LeetCode】1371. 每个元音包含偶数次的最长子字符串
【LeetCode】680. 验证回文字符串 Ⅱ
【剑指Offer】面试题46. 把数字翻译成字符串
【剑指Offer】面试题45. 把数组排成最小的数
原文地址:https://www.cnblogs.com/silva/p/1044638.html
最新文章
第十一周学习进度条
个人工作总结05
典型用户和用户场景描述
个人工作总结04
个人工作总结03
个人工作总结02
个人工作总结01
第十周学习进度条
第九周学习进度条
boa移植过程中出现的问题
热门文章
嵌入式boa服务器移植
make: yacc:命令未找到
MAC地址和IP地址的区别
常见的几种嵌入式web服务器
C++后台开发面试考点汇总
求GCD(最大公约数)的两种方式
ubuntu 启动程序后显示对话框 网络服务探测被禁用,您当前的网络有.local域,我们不建议这样做,而且这与Avahi网络服务探测不兼容
VMware虚拟机三种网络模式详解 Bridged(桥接模式)
VMware网络连接模式(桥接、NAT以及仅主机模式的详细介绍和区别)
什么是同一网段
Copyright © 2011-2022 走看看