XMLHttpRequest.onreadystatechange方法未运行 [英] XMLHttpRequest.onreadystatechange Method Not Running

查看:726
本文介绍了XMLHttpRequest.onreadystatechange方法未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在写一个网络应用程序的问题。我有一个

的表格,我将验证其中一个字段。我使用AJAX检索包含有效条目列表的
XML。我的应用程序在IE下工作,奇怪的是

足够了。但是,在Firefox下,似乎没有调用

XMLHttpRequest.onreadystatechange方法。

代码如下。我正在使用同步模式因为我认为我需要在ajaxGetGroupUserListXML()返回之前将全局变量g_groupListXML包含在

xmlHttp.responseText中。我在这一点上是否支持



函数getXMLHTTPRequestObject()

{

var xmlHttp = null;

尝试

{

// Firefox,Opera 8.0 +,Safari

xmlHttp = new XMLHttpRequest ();

}

catch(e)

{

// Internet Explorer

尝试

{

xmlHttp = new ActiveXObject(" Msxml2.XMLHTTP");

}

catch(e)

{

try

{

xmlHttp = new ActiveXObject(" Microsoft.XMLHTTP" ;);

}

catch(e)

{

alert("您的浏览器不支持AJAX!");

}

}

}

返回xmlHttp;

}

var g_groupListXML = null;


函数ajaxGetGroupUserListXML(url)

{

var xmlHttp = null;

xmlHttp = getXMLHTTPRequestObject();

xmlHttp.onreadystatechange = function ()

{

如果

(xmlHttp.readyState == 4)

{


alert(" onreadystatechange called ...");


g_groupListXML = xmlHttp.responseText;

}

}

xmlHttp.open(" GET",url,false);

xmlHttp.send(null);

}


函数getGroupListXML(表格)

{

var retval = false;

var xmlDoc = null;

var doc = null;

ajaxGetGroupUserListXML(''XMLProducingScript.cfm'');


//解析检索到的XML

if(window.ActiveXObject)

{

doc = new ActiveXObject(" Microsoft.XMLDOM") ;

doc.async =" false" ;;

doc.loadXML(g_groupListXML);

}

否则

{

var parser = new DOMParser();

doc = parser.parseFromString(g_groupListXML," text / xml");

}


xmlDoc = d oc.documentElement;

form.fieldx.value = trim(form.fieldx.value);


for(var i = 0;我< xmlDoc.childNodes.length; i ++)

{

if(xmlDoc.childNodes [i] .childNodes [0] .nodeValue.toLower()==

表格。 group_name.value.toLowerCase())

{

alert(''String already used'');

retval = true;

休息;

}

}

返回retval;

}

Hi All,

I''m having a problem with a web app I''m writing. I have a form for
which I''m going to validate one of the fields. I use AJAX to retrieve
XML containing a list of valid entries. My app works under IE, oddly
enough. But, under Firefox, it seems that the
XMLHttpRequest.onreadystatechange method is not being called. The
code follows. I''m using synchronous mode because I''m thinking that I
want that global variable g_groupListXML to contain
xmlHttp.responseText before ajaxGetGroupUserListXML( ) returns. Am I
right on this point?

function getXMLHTTPRequestObject( )
{
var xmlHttp = null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
}
}
}
return xmlHttp;
}
var g_groupListXML = null;

function ajaxGetGroupUserListXML(url)
{
var xmlHttp = null;
xmlHttp = getXMLHTTPRequestObject( );
xmlHttp.onreadystatechange = function ()
{
if
(xmlHttp.readyState == 4)
{

alert("onreadystatechange called...");

g_groupListXML = xmlHttp.responseText;
}
}
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
}

function getGroupListXML(form)
{
var retval = false;
var xmlDoc = null;
var doc = null;

ajaxGetGroupUserListXML(''XMLProducingScript.cfm'');

// Parse retrieved XML
if (window.ActiveXObject)
{
doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML(g_groupListXML);
}
else
{
var parser = new DOMParser( );
doc = parser.parseFromString(g_groupListXML, "text/xml");
}

xmlDoc = doc.documentElement;
form.fieldx.value = trim(form.fieldx.value);

for (var i = 0; i < xmlDoc.childNodes.length; i++)
{
if (xmlDoc.childNodes[i].childNodes[0].nodeValue.toLower( ) ==
form.group_name.value.toLowerCase())
{
alert(''String already used'');
retval = true;
break;
}
}
return retval;
}

推荐答案

HugeBob写道:
HugeBob wrote:

大家好,

我正在写一个网络应用程序的问题。我有一个

的表格,我将验证其中一个字段。我使用AJAX检索包含有效条目列表的
XML。我的应用程序在IE下工作,奇怪的是

足够了。但是,在Firefox下,似乎没有调用

XMLHttpRequest.onreadystatechange方法。

代码如下。我正在使用同步模式因为我认为我需要在ajaxGetGroupUserListXML()返回之前将全局变量g_groupListXML包含在

xmlHttp.responseText中。我在这一点上是否支持

Hi All,

I''m having a problem with a web app I''m writing. I have a form for
which I''m going to validate one of the fields. I use AJAX to retrieve
XML containing a list of valid entries. My app works under IE, oddly
enough. But, under Firefox, it seems that the
XMLHttpRequest.onreadystatechange method is not being called. The
code follows. I''m using synchronous mode because I''m thinking that I
want that global variable g_groupListXML to contain
xmlHttp.responseText before ajaxGetGroupUserListXML( ) returns. Am I
right on this point?



如果你做了一个
$你就不必为onreadystatechange打扰b $ b同步请求,只需使用responseXML / Text。

-

Ian Collins。

You don''t have to bother with onreadystatechange if you make a
synchronous request, just use the responseXML/Text.
--
Ian Collins.


" ;伊恩柯林斯 < ia ****** @ hotmail.comwrote in message

news:57 ************** @ mid.individual.net ...
"Ian Collins" <ia******@hotmail.comwrote in message
news:57**************@mid.individual.net...

HugeBob写道:
HugeBob wrote:

>大家好,

我是'我正在写一个网络应用程序的问题。我有一个
表格,我将验证其中一个字段。我使用AJAX来检索包含有效条目列表的XML。我的应用程序在IE下工作,奇怪
足够。但是,在Firefox下,似乎没有调用
XMLHttpRequest.onreadystatechange方法。
代码如下。我正在使用同步模式,因为我想在ajaxGetGroupUserListXML()返回之前我希望全局变量g_groupListXML包含
xmlHttp.responseText。我在这一点上是对的吗?
>Hi All,

I''m having a problem with a web app I''m writing. I have a form for
which I''m going to validate one of the fields. I use AJAX to retrieve
XML containing a list of valid entries. My app works under IE, oddly
enough. But, under Firefox, it seems that the
XMLHttpRequest.onreadystatechange method is not being called. The
code follows. I''m using synchronous mode because I''m thinking that I
want that global variable g_groupListXML to contain
xmlHttp.responseText before ajaxGetGroupUserListXML( ) returns. Am I
right on this point?



如果你做了一个

同步,你不必费心onreadystatechange请求,只需使用responseXML / Text。

You don''t have to bother with onreadystatechange if you make a
synchronous request, just use the responseXML/Text.



嗯,如果你需要进行同步调用,你需要重新考虑你的AJAX。

http://ajaxblog.com/archives/2005/05...s-requests-bad 仅举一例。


-Lost

Um, if you have to make synchronous calls you need to rethink your AJAX.

http://ajaxblog.com/archives/2005/05...s-requests-bad for just one example.

-Lost


-Lost写道:
-Lost wrote:

" Ian Collins" < ia ****** @ hotmail.comwrote in message

news:57 ************** @ mid.individual.net ...
"Ian Collins" <ia******@hotmail.comwrote in message
news:57**************@mid.individual.net...

>> HugeBob写道:
>>HugeBob wrote:

>>>大家好,

我正在写一个Web应用程序的问题。我有一个
表格,我将验证其中一个字段。我使用AJAX来检索包含有效条目列表的XML。我的应用程序在IE下工作,奇怪
足够。但是,在Firefox下,似乎没有调用
XMLHttpRequest.onreadystatechange方法。
代码如下。我正在使用同步模式,因为我想在ajaxGetGroupUserListXML()返回之前我希望全局变量g_groupListXML包含
xmlHttp.responseText。我在这一点上是否正确?
>>>Hi All,

I''m having a problem with a web app I''m writing. I have a form for
which I''m going to validate one of the fields. I use AJAX to retrieve
XML containing a list of valid entries. My app works under IE, oddly
enough. But, under Firefox, it seems that the
XMLHttpRequest.onreadystatechange method is not being called. The
code follows. I''m using synchronous mode because I''m thinking that I
want that global variable g_groupListXML to contain
xmlHttp.responseText before ajaxGetGroupUserListXML( ) returns. Am I
right on this point?


如果您发出
同步请求,您不必费心onreadystatechange,只需使用responseXML / Text 。


You don''t have to bother with onreadystatechange if you make a
synchronous request, just use the responseXML/Text.




嗯,如果你需要进行同步通话,你需要重新考虑你的AJAX。



Um, if you have to make synchronous calls you need to rethink your AJAX.



如果要求获取信息需要继续,请加载

界面说明。


-

Ian Collins。

Not if it''s a call to get information required to carry on, loading an
interface description for example.

--
Ian Collins.


这篇关于XMLHttpRequest.onreadystatechange方法未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆