手机校园网连不上突然连不上了,总是弹出来object XML HttpRequest,怎么去掉呀

js建立XMLHttpRequest对象及其属性和方法
js建立XMLHttpRequest对象及其属性和方法
var&xmlH &&
function&creatXMLHttpRequest() &&
&&&&if(window.ActiveXObject) &&
&&&&&&&&xmlHttp=new&ActiveXObject("Microsoft.XMLHTTP"); &&
&&&&else&if(window.XMLHttpRequest) &&
&&&&&&&&xmlHttp=new&XMLHttpRequest(); &&
function&callServer() &&
&&&&creatXMLHttpRequest() &&
&&&&var&email=document.getElementById("TxtEmail"). &&
&&&&if(email=="") &&
&&&&&&&&document.getElementById("LabMsg").innerText="请输入邮箱!"; &&
&&&&&&&&document.getElementById("LabMsg").style.color="red"; &&
&&&&else&&
&&&&&&&&url="register.aspx?email="&+&email&+&"&ts"&+&new&Date().getTime(); &&
&&&&&&&&xmlHttp.onreadystatechange=handleStateC &&
&&&&&&&&xmlHttp.open("GET",url,true); &&
&&&&&&&&xmlHttp.send(null); &&
function&handleStateChange() &&
&&&&if(xmlHttp.readyState==4) &&
&&&&&&&&&&
&&&&&&&&if(xmlHttp.status==200) &&
&&&&&&&&{ &&
&&&&&&&&&&&&var&result=xmlHttp.responseXML.getElementsByTagName("result")[0].firstChild.nodeV &&
&&&&&&&&&&&&if(result=="true") &&
&&&&&&&&&&&&{ &&
&&&&&&&&&&&&&&&&document.getElementById("LabMsg").innerHTML="恭喜,可用!"; &&
&&&&&&&&&&&&&&&&document.getElementById("LabMsg").style.color="red"; &&
&&&&&&&&&&&&} &&
&&&&&&&&&&&&else&if(result=="false") &&
&&&&&&&&&&&&{ &&
&&&&&&&&&&&&&&&&document.getElementById("LabMsg").innerText="该邮箱已存在!"; &&
&&&&&&&&&&&&&&&&document.getElementById("LabMsg").style.color="red"; &&
&&&&&&&&&&&&} &&
&&&&&&&&} &&
post请求 &&
&&&&url="register.aspx?email="&+&email&+&"&ts"&+&new&Date().getTime(); &&
&&&xmlHttp.onreadystatechange=handleStateC &&
&&&xmlHttp.open("POST",url,false);&&&&&&&&&&& &&
&&&xmlHttp.SetRequestHeader("Content-Type","application/x-www-form-urlencoded");&&&&&&&&&&& &&
&&&xmlHttp.send(null);&&
//定义变量,存储对象
//创建XMLHttpRequest对象
function creatXMLHttpRequest()
if(window.ActiveXObject)
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
xmlHttp=new XMLHttpRequest();
//使用get方式建立与后台的交互
function callServer()
creatXMLHttpRequest()
var email=document.getElementById("TxtEmail").
if(email=="")
document.getElementById("LabMsg").innerText="请输入邮箱!";
document.getElementById("LabMsg").style.color="red";
url="register.aspx?email=" + email + "&ts" + new Date().getTime();
xmlHttp.onreadystatechange=handleStateC
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
//回调函数,后台处理完结果后返回给回调函数
function handleStateChange()
//请求的状态有5个值:0=未初始化;1=正在加载;2=已经加载;3=交互中;4=完成;
if(xmlHttp.readyState==4)
//200对应OK,如404=未找到网页
if(xmlHttp.status==200)
var result=xmlHttp.responseXML.getElementsByTagName("result")[0].firstChild.nodeV
if(result=="true")
document.getElementById("LabMsg").innerHTML="恭喜,可用!";
document.getElementById("LabMsg").style.color="red";
else if(result=="false")
document.getElementById("LabMsg").innerText="该邮箱已存在!";
document.getElementById("LabMsg").style.color="red";
//使用post请求
url="register.aspx?email=" + email + "&ts" + new Date().getTime();
xmlHttp.onreadystatechange=handleStateC
xmlHttp.open("POST",url,false);
xmlHttp.SetRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(null);
后台处理请求的代码:
&&&&&&&&string&& &&
&&&&&&&&email&=&Request.QueryString["email"]; &&
&&&&&&&&myCustomer.Email&=& &&
&&&&&&&&if&(email&==&string.Empty&||&email&==&null) &&
&&&&&&&&{ &&
&&&&&&&&&&&&return; &&
&&&&&&&&} &&
&&&&&&&&else&&
&&&&&&&&{ &&
&&&&&&&&&&&&StringBuilder&result&=&new&StringBuilder("&result&"); &&
&&&&&&&&&&&&if&(myCheck.HaveCustomer(myCustomer)) &&
&&&&&&&&&&&&{ &&
&&&&&&&&&&&&&&&&result.Append("false"); &&
&&&&&&&&&&&&&&&&result.Append("&/result&"); &&
&&&&&&&&&&&&&&&&Response.ContentType&=&"text/xml"; &&
&&&&&&&&&&&&&&&&Response.Write(result.ToString()); &&
&&&&&&&&&&&&&&&&Response.End(); &&
&&&&&&&&&&&&} &&
&&&&&&&&&&&&else&&
&&&&&&&&&&&&{ &&
&&&&&&&&&&&&&&&&result.Append("true"); &&
&&&&&&&&&&&&&&&&result.Append("&/result&"); &&
&&&&&&&&&&&&&&&&Response.ContentType&=&"text/xml"; &&
&&&&&&&&&&&&&&&&Response.Write(result.ToString()); &&
&&&&&&&&&&&&&&&&Response.End(); &&
&&&&&&&&&&&&} &&
&&&&&&&&}&&
//写在所请求的URL页面的page_load下
email = Request.QueryString["email"];
myCustomer.Email =
if (email == string.Empty || email == null)
StringBuilder result = new StringBuilder("&result&");
if (myCheck.HaveCustomer(myCustomer))
result.Append("false");
result.Append("&/result&");
Response.ContentType = "text/xml";
Response.Write(result.ToString());
Response.End();
result.Append("true");
result.Append("&/result&");
Response.ContentType = "text/xml";
Response.Write(result.ToString());
Response.End();
XMLHttpRequest
&&&& XMLHttpRequestXMLHttpRequest
1. readyState
XMLHttpRequestHTTPXMLHttpRequestreadyState
2. onreadystatechange
readyStateXMLHttpRequestreadystatechangeonreadystatechangeEventListenerreadyState
3. responseText
responseTextHTTPreadyState012responseTextreadyState3readyState4responseText
4. responseXML
HTTPreadyState4XMLContent-TypeMIMEtext/xmlapplication/xml+xmlContent-TyperesponseXMLnullreadyState4responseXMLnull
responseXMLresponseXMLnull
HTTPshortreadyState34statusreadyState3statusstatus200404
6. statusText
HTTPreadyState34readyStatestatusText
XMLHttpRequest
XMLHttpRequest
方法:open创建一个新的http请求,并指定此请求的方法、URL以及验证信息语法:oXMLHttpRequest.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword);参数bstrMethodhttp方法,例如:POST、GET、PUT及PROPFIND。大小写不敏感。 bstrUrl请求的URL地址,可以为绝对地址也可以为相对地址。 varAsync[可选]布尔型,指定此请求是否为异步方式,默认为true。如果为真,当状态改变时会调用onreadystatechange属性指定的回调函数。 bstrUser[可选]如果服务器需要验证,此处指定用户名,如果未指定,当服务器需要验证时,会弹出验证窗口。 bstrPassword[可选]验证信息中的密码部分,如果用户名为空,则此值将被忽略。
备注:调用此方法后,可以调用send方法向服务器发送数据。xmlhttp.Open("get", "http://localhost/example.htm", false);
方法:send发送请求到http服务器并接收回应语法:xmlhttp.send(varBody);参数:varBody (欲通过此请求发送的数据。) 备注:此方法的同步或异步方式取决于open方法中的bAsync参数,如果bAsync == False,此方法将会等待请求完成或者超时时才会返回,如果bAsync == True,此方法将立即返回。&如果发送的数据为BSTR,则回应被编码为utf-8, 必须在适当位置设置一个包含charset的文档类型头。&如果发送的数据为XML DOM object,则回应将被编码为在xml文档中声明的编码,如果在xml文档中没有声明编码,则使用默认的UTF-8。&xmlhttp.Send(xmldoc);
方法:getAllResponseHeaders获取响应的所有http头语法:strValue = xmlhttp.getAllResponseHeaders();备注:每个http头名称和值用冒号分割,并以rn结束。当send方法完成后才可调用该方法。 alert(xmlhttp.getAllResponseHeaders());
方法:getResponseHeader从响应信息中获取指定的http头语法:strValue = xmlhttp.getResponseHeader(bstrHeader);备注:当send方法成功后才可调用该方法。如果服务器返回的文档类型为"text/xml", 则这句话xmlhttp.getResponseHeader("Content-Type");将返回字符串"text/xml"。可以使用getAllResponseHeaders方法获取完整的http头信息。 alert(xmlhttp.getResponseHeader("Content-Type")); // 输出http头中的Content-Type列:当前web服务器的版本及名称。
方法:abort取消当前请求语法:xmlhttp.abort();备注:调用此方法后,当前请求返回UNINITIALIZED 状态。
方法:setRequestHeader单独指定请求的某个http头语法:xmlhttp.setRequestHeader(bstrHeader, bstrValue);参数:bstrHeader(字符串,头名称。) bstrValue(字符串,值。) 备注:如果已经存在已此名称命名的http头,则覆盖之。此方法必须在open方法后调用。xmlhttp.setRequestHeader(bstrHeader, bstrValue);
发表评论:
TA的最新馆藏[转]&[转]&[转]&[转]&[转]&[转]&window.ActiveXObject XMLHTTPRequest对象-js教程-网页制作-壹聚教程网window.ActiveXObject XMLHTTPRequest对象
XMLHTTPRequest对象发送请求和处理响应之前,我们必须要用javascript创建一个XMLHTTPRequest对象。(IE把XMLHTTPRequest实现为一个ActiveX对象,其他的浏览器[如Firefox/Safari/Opear]则把它实现为一个本地的javascript对象)。
创建xmlhttprequest对象
activexobject 对象
启用并返回 automation 对象的引用。
newobj = new activexobject(servername.typename[, location])
activexobject 对象语法有这些部分:
必选项。要赋值为 activexobject 的变量名。
servername
必选项。提供该对象的应用程序的名称。
必选项。要创建的对象的类型或类。
可选项。创建该对象的网络服务器的名称。
automation 服务器至少提供一类对象。例如,字处理应用程序可能提供应用程序对象、文档对象和工具栏对象。
要创建 automation 对象,将新的 activexobject 赋给对象变量:&
excelapp = new activexobject(&excel.application&);
excelsheet = new activexobject(&excel.sheet&);
本代码启动创建对象的应用程序(在这种情况下,microsoft excel 工作表)。一旦对象被创建,就可以用定义的对象变量在代码中引用它。 在下面的例子中,通过对象变量 excelsheet 访问新对象的属性和方法和其他 excel 对象,包括 application 对象和 activesheet.cells 集合。&
// 使 excel 通过 application 对象可见。
excelsheet.application.visible =
// 将一些文本放置到表格的第一格中。
excelsheet.activesheet.cells(1,1).value = &this is column a, row 1&;
// 保存表格。
excelsheet.saveas(&c:www.111cn.nettest.xls&);
// 用 application 对象用 quit 方法关闭 excel。
excelsheet.application.quit();
只有当 internet 安全性关闭时才能完成在远程服务器中创建对象。要在远程网络计算机创建对象,可以将该计算机的名称传递给 activexobject 的 servername 参数。该名称与共享名的机器名部分相同。比如共享名为 &myserverpublic& 的网络,servername 是 &myserver&。另外,可以用 dns 格式或 ip 地址指定 servername。
下面的代码返回在名为 &myserver& 的远程网络计算机上运行的 excel 实例的版本号:
function getappversion() {
& var xlapp = new activexobject(&excel.application&, &myserver&);
& return(xlapp.version);
用来区别ie与其他浏览器及ie6-8之间的方法。
1、document.all
2、!!window.
使用方法如下:
if (document.all){
alert(&ie浏览器&);
alert(&非ie浏览器&);
if (!!window.activexobject){
alert(&ie浏览器&);
alert(&非ie浏览器&);
var isie=!!window.
var isie6=isie&&!window.
var isie8=isie&&!!document.
var isie7=isie&&!isie6&&!isie8;
if (isie){
if (isie6){
alert(&ie6&);
}else if (isie8){
alert(&ie8&);
}else if (isie7){
alert(&ie7&);
在使用xmlhttprequest对象发送请求和处理响应之前,我们必须要用创建一个xmlhttprequest对象。(ie把xmlhttprequest实现为一个activex对象,其他的浏览器[如firefox/safari/opear]则把它实现为一个本地的javascript对象)。
&script language=&javascript& type=&text/javascript&&
// 创建xmlhttprequest对象
function createxmlhttprequest(){
if(window.activexobject){ // 判断是否支持activex控件
xmlhttp = new activeobject(&microsoft.xmlhttp&); // 通过实例化activexobject的一个新实例来创建xmlhttprequest对象
else if(window.xmlhttprequest){ // 判断是否把xmlhttprequest实现为一个本地javascript对象
xmlhttp = new xmlhttprequest(); // 创建xmlhttprequest的一个实例(本地javascript对象)
window.activexobject的调用会返回一个对象,也可能返回null,if语句会把返回的结果看作是true或false,如果返回对象则为true,返回null则为false,以此指示浏览器是否支持activex控件,相应的得知浏览器是不是internet explorer.
上一页: &&&&&下一页:相关内容5845人阅读
问题描述:使用jquery进行ajax&post请求时,报错,提示[object XMLHttpRequest],在谷歌浏览器中发现此问题,IE7/8/9/10都没问题
同时在事件查看器中也相应发现如下事件内容:
Event code: 3005
Event message: 发生了未处理的异常。
Event time:
Event time (UTC):
Event ID: b3b2dd2f8f51cfabbfb6
Event sequence: 74
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/2/ROOT-8-222308
Trust level: Full
Application Virtual Path: /
Application Path: D:\Project\Portal\code\MaintenanceSystem.Web\
Machine name: PC
Process information:
Process ID: 3876
Process name: w3wp.exe
Account name: PC\Administrator
Exception information:
Exception type: HttpException
Exception message: 远程主机关闭了连接。错误代码是 0x。
Request information:
Request URL: http://localhost:8001/WebService/DataSync.aspx
Request path: /WebService/DataSync.aspx
User host address: ::1
Is authenticated: False
Authentication Type:
Thread account name: PC\Administrator
Thread information:
Thread ID: 16
Thread account name: PC\Administrator
Is impersonating: False
Stack trace:
在 System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
在 System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
在 System.Web.HttpResponse.Flush(Boolean finalFlush)
在 System.Web.UI.HtmlTextWriter.Write(String s)
在 System.Web.UI.LiteralControl.Render(HtmlTextWriter output)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Page.Render(HtmlTextWriter writer)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
前台请代码如下:
url: '/WebService/DataSync.aspx',
type: 'POST',
data: { Action: &GETCATEGORYCODE&, CategoryId: cid, ParentId: pid, Order: order },
dataType: 'text',
timeout: 1000,
error: function(ex) { alert(ex); },
success: function(result) {
var r = result.split(&:&);
$('#&%=txtCategoryCode.ClientID %&').val(r[1]);
if (r[0] == &true&) {
$('#&%=txtCategoryCode.ClientID %&').next().hide();
$('#&%=RequiredFieldValidator2.ClientID %&').show();
$('#&%=RequiredFieldValidator2.ClientID %&').html(&编码已存在&);
$('#&%=btnSave.ClientID %&').attr(&disabled&, true);
$('#&%=txtCategoryCode.ClientID %&').next().show();
$('#&%=RequiredFieldValidator2.ClientID %&').hide();
$('#&%=btnSave.ClientID %&').attr(&disabled&, false);
后台DataSync.aspx.cs代码如下:
protected void Page_Load(object sender, EventArgs e)
Response.Clear();
Response.BufferOutput =
Response.ContentEncoding = System.Text.Encoding.UTF8;
switch (Action)
case DataSyncAction.GetCategoryCode:
GetCategoryCode();
Response.Flush();
Response.End();
Response.Close();
解决方法:
发现在以上后台代码中如果将Response.BufferOutput的值改为true现象1仍然存在,但现象2消失,如果进一步将以上代码中的Response.Flush();去掉的话则问题解决。
正确代码如下:
protected void Page_Load(object sender, EventArgs e)
Response.Clear();
Response.BufferOutput =
Response.ContentEncoding = System.Text.Encoding.UTF8;
switch (Action)
case DataSyncAction.GetCategoryCode:
GetCategoryCode();
//Response.Flush();去掉此句代码
Response.End();
Response.Close();
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:48793次
排名:千里之外
原创:16篇
(1)(4)(3)(1)(1)(4)(2)(7)XMLHttpRequest 对象
XMLHttpRequest 对象
XMLHttpRequest 对象用于在后台与服务器交换数据。
什么是 XMLHttpRequest 对象?
XMLHttpRequest 对象用于在后台与服务器交换数据。
XMLHttpRequest 对象是开发者的梦想,因为您能够:
在不重新加载页面的情况下更新网页
在页面已加载后从服务器请求数据
在页面已加载后从服务器接收数据
在后台向服务器发送数据
所有现代的浏览器都支持 XMLHttpRequest 对象。
如需学习更多有关 XMLHttpRequest 对象的知识,请学习我们的 。
创建 XMLHttpRequest 对象
所有现代浏览器 (IE7+、Firefox、Chrome、Safari 以及 Opera) 都内建了 XMLHttpRequest 对象。
通过一行简单的 JavaScript 代码,我们就可以创建 XMLHttpRequest 对象。
创建 XMLHttpRequest 对象的语法:
xmlhttp=new XMLHttpRequest();
老版本的 Internet Explorer (IE5 和 IE6)使用 ActiveX 对象:
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
提示:在下一章,我们将使用 XMLHttpRequest 对象从服务器取回 XML 信息。
&script type=&text/javascript&&
function loadXMLDoc(url)
if (window.XMLHttpRequest)
{// code for all new browsers
xmlhttp=new XMLHttpRequest();
else if (window.ActiveXObject)
{// code for IE5 and IE6
xmlhttp=new ActiveXObject(&Microsoft.XMLHTTP&);
if (xmlhttp!=null)
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open(&GET&,url,true);
xmlhttp.send(null);
alert(&Your browser does not support XMLHTTP.&);
function state_Change()
if (xmlhttp.readyState==4)
{// 4 = &loaded&
if (xmlhttp.status==200)
{// 200 = OK
// ...our code here...
alert(&Problem retrieving XML data&);
注释:onreadystatechange 是一个事件句柄。它的值 (state_Change) 是一个函数的名称,当 XMLHttpRequest 对象的状态发生改变时,会触发此函数。状态从 0 (uninitialized) 到 4 (complete) 进行变化。仅在状态为 4 时,我们才执行代码。
为什么使用 Async=true ?
我们的实例在 open() 的第三个参数中使用了 &true&。
该参数规定请求是否异步处理。
True 表示脚本会在 send() 方法之后继续执行,而不等待来自服务器的响应。
onreadystatechange 事件使代码复杂化了。但是这是在没有得到服务器响应的情况下,防止代码停止的最安全的方法。
通过把该参数设置为 &false&,可以省去额外的 onreadystatechange 代码。如果在请求失败时是否执行其余的代码无关紧要,那么可以使用这个参数。
您也可以把 XML 文档打开并发送到服务器上的 ASP 页面,分析此请求,然后传回结果。
&script type=&text/javascript&&
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlHttp=new XMLHttpRequest();
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlHttp=new ActiveXObject(&Microsoft.XMLHTTP&);
if (xmlHttp!=null)
xmlHttp.open(&GET&, &note.xml&, false);
xmlHttp.send(null);
xmlDoc=xmlHttp.responseT
xmlHttp.open(&POST&, &demo_dom_http.asp&, false);
xmlHttp.send(xmlDoc);
document.write(xmlHttp.responseText);
alert(&Your browser does not support XMLHTTP.&);
ASP 页面,由 VBScript 编写:
set xmldoc = Server.CreateObject(&Microsoft.XMLDOM&)
xmldoc.async=false
xmldoc.load(request)
for each x in xmldoc.documentElement.childNodes
if x.NodeName = &to& then name=x.text
response.write(name)
通过使用 response.write 属性把结果传回客户端。
XMLHttpRequest 对象是 W3C 的标准吗?
任何 W3C 推荐标准均未规定 XMLHttpRequest 对象。
不过,W3C DOM Level 3 的 &Load and Save& 规范包含了一些相似的功能性,但是还没有任何浏览器实现它们。

我要回帖

更多关于 校园网连不上 的文章

 

随机推荐