ajax怎么获取request
展开全部
1、这是Ajax异步Request:
<script type="text/javascript"><!--
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request) alert("Error initializing XMLHttpRequest!");
//获取信息
function GetInfo() {
var url = "test.aspx?userName=" + document.getElementById("txtName").value;
request.open("GET", url, true);
request.onreadystatechange = updatePageTime;
request.send(null);
}
//更新页面
function updatePageTime() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText;
document.getElementById("txtLoginName").value = response;
} else if (request.status == 404) {
alert("Requested URL is not found.");
} else if (request.status == 403) {
alert("Access denied.");
} else
alert("status is " + request.status);
}
}
// --></script>
<form id="form1" runat="server">
<input id="txtName" onchange="GetInfo()" type="text" />
<input id="txtLoginName" type="text" />
</form>
2、下面是我对你的题目的自己的想法
{
action : 'online_state',
params : {
state : fld.value
}
}
这种方式叫字面量写法,也可以叫json写法
原理是大括号代表对象,中括号代表集合,大括号里面用字符串或者对象当做属性,加冒号来表示赋值
由于JavaScript若类型语言的特性,可以把一个大括号包住的对象赋值给一个属性
举例
翻译成类写法就是
a = 1;
b = 2;
同理}
翻译一下就是
a = 1;
b = {
aa=2;
bb=3;
}
希望对你有帮助!
<script type="text/javascript"><!--
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request) alert("Error initializing XMLHttpRequest!");
//获取信息
function GetInfo() {
var url = "test.aspx?userName=" + document.getElementById("txtName").value;
request.open("GET", url, true);
request.onreadystatechange = updatePageTime;
request.send(null);
}
//更新页面
function updatePageTime() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText;
document.getElementById("txtLoginName").value = response;
} else if (request.status == 404) {
alert("Requested URL is not found.");
} else if (request.status == 403) {
alert("Access denied.");
} else
alert("status is " + request.status);
}
}
// --></script>
<form id="form1" runat="server">
<input id="txtName" onchange="GetInfo()" type="text" />
<input id="txtLoginName" type="text" />
</form>
2、下面是我对你的题目的自己的想法
{
action : 'online_state',
params : {
state : fld.value
}
}
这种方式叫字面量写法,也可以叫json写法
原理是大括号代表对象,中括号代表集合,大括号里面用字符串或者对象当做属性,加冒号来表示赋值
由于JavaScript若类型语言的特性,可以把一个大括号包住的对象赋值给一个属性
举例
翻译成类写法就是
a = 1;
b = 2;
同理}
翻译一下就是
a = 1;
b = {
aa=2;
bb=3;
}
希望对你有帮助!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询