AJAX问题 [英] AJAX Issue

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

问题描述

我正在使用AJAX XMLhttprequest来请求表单上的另一个页面提交

并且我将该页面加载到span标记中。我的问题是,我在被调用的页面中有更多的js来点击文本

框来加载日历。这个日历永远不会加载到我的页面中,但是如果我在新窗口中通过

本身调用页面,javascript工作正常,任何想法?见下面

当你打电话给索引并点击按钮时页面没有显示

警报,当你直接打电话给getcall时,警报显示正常。

index.asp

< form name =" new" method =" Post"

action =" javascript :get(document.getElementById(''ne w''),''new'');" >

< input type ="提交"命名= [提交" value =" Enter New Call">< br>

< / form>

< span name =" call_results" id =" call_results">< / span>

getcall.asp

< SCRIPT type =" text / javascript">

alert(" here");

< / SCRIPT>


js。

/ *表单上的AJAX提交* /

var http_request = false;

函数makePOSTRequest(url,parameters){

http_request = false;

if(window.XMLHttpRequest){// Mozilla,Safari,...

http_request = new XMLHttpRequest();

if(http_request。 overrideMimeType){

http_request.overrideMimeType(''text / xml'');

}

} else if(window.ActiveXObject){ // IE

尝试{

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

} catch(e){

尝试{

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

} catch(e){}

}

}

if(!http_request){

alert(''无法创建XMLHTTP实例'');

返回false;

}


http_request.onreadystatechange = alertContents;

http_request.open(''POST'',url,true);

http_request.setRequestHeader(" Content-type",

" application / x- www-form-urlencoded");

http_request.setRequestHeader(" Content-length",parameters.length);

http_request.setRequestHeader(" Connection"," ;关闭);

http_request.send(参数);

toggleT(''call_mainscreen'',''h'')

}


函数alertContents(){

// if(http_request.readyState == 4){

// if( http_request.status == 200){

//alert(http_request.responseText);

// result = http_request.responseText;

/ / document.getElementById(''call_results'')。innerHTML = result;


//} else {

// alert(''有一个请求的问题。'');

//}

//}

if(http_request.readyState == 4){

strResponse = http_request.responseText;

switch(http_request.status){

//页面未找到错误

案例404:

alert(''错误:未找到。找不到请求的网址''

strURL +''。'');

break;

//显示结果服务器端错误的完整窗口

案例500:

handleErrFullPage(strResponse);

休息;

默认值:

//调用JS警报以获取自定义错误或调试消息

if(strResponse.indexOf(''错误:'')> -1 ||

strResponse.indexOf(''Debug:'')> -1){

alert(strResponse);

}

//调用所需的结果函数

else {

result = http_request.responseText;

document.getElementById(''call_results' ').innerHTML =结果;

}

休息;

}

}

}

函数handleErrFullPage(strIn){


var errorWin;


//创建新窗口显示错误

尝试{

errorWin = window.open('''',''errorWin'');

errorWin.document.body.innerHTML = strIn;

}

//如果弹出窗口被阻止,请通知用户

catch(e){

alert(''发生了错误,但错误信息无法显示,因为'b $ b''显示为'$ + $ / b $ b''因为你的浏览器的弹出窗口

blocker.\
''+

''请允许来自这个网站的弹出窗口。'') ;

}

}

函数get(obj,itype){

var poststr =" type = " + itype +"& value = test";

makePOSTRequest(''getcall.asp'',poststr);

}

I am using AJAX XMLhttprequest to request another page on form submit
and I am loading that page into a span tag. My issue is that I have
more js in the called page that loads a calendar on click of a text
box. This calendar never loads in my page but if I call the page by
itself in a new window javascript works fine, any ideas? See Below
when you call index and click the button the page does not show the
alert, when you call getcall straight the alert shows fine.
index.asp
<form name="new" method="Post"
action="javascript:get(document.getElementById(''ne w''),''new'');">
<input type="Submit" name="Submit" value="Enter New Call"><br>
</form>
<span name="call_results" id="call_results"></span>

getcall.asp
<SCRIPT type="text/javascript">
alert("here");
</SCRIPT>

js.
/* AJAX on form submit */
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType(''text/xml'');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert(''Cannot create XMLHTTP instance'');
return false;
}

http_request.onreadystatechange = alertContents;
http_request.open(''POST'', url, true);
http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
toggleT(''call_mainscreen'',''h'')
}

function alertContents() {
//if (http_request.readyState == 4) {
//if (http_request.status == 200) {
//alert(http_request.responseText);
// result = http_request.responseText;
// document.getElementById(''call_results'').innerHTML = result;

//} else {
// alert(''There was a problem with the request.'');
//}
//}
if (http_request.readyState == 4) {
strResponse = http_request.responseText;
switch (http_request.status) {
// Page-not-found error
case 404:
alert(''Error: Not Found. The requested URL '' +
strURL + '' could not be found.'');
break;
// Display results in a full window for server-side errors
case 500:
handleErrFullPage(strResponse);
break;
default:
// Call JS alert for custom error or debug messages
if (strResponse.indexOf(''Error:'') > -1 ||
strResponse.indexOf(''Debug:'') > -1) {
alert(strResponse);
}
// Call the desired result function
else {
result = http_request.responseText;
document.getElementById(''call_results'').innerHTML = result;
}
break;
}
}
}
function handleErrFullPage(strIn) {

var errorWin;

// Create new window and display error
try {
errorWin = window.open('''', ''errorWin'');
errorWin.document.body.innerHTML = strIn;
}
// If pop-up gets blocked, inform user
catch(e) {
alert(''An error occurred, but the error message cannot
be'' +
'' displayed because of your browser\''s pop-up
blocker.\n'' +
''Please allow pop-ups from this Web site.'');
}
}
function get(obj,itype) {
var poststr = "type=" + itype + "&value=test";
makePOSTRequest(''getcall.asp'', poststr);
}

推荐答案

wh****@gmail.com 说以下是2006年6月26日下午2:43:
wh****@gmail.com said the following on 6/26/2006 2:43 PM:
我正在使用AJAX XMLhttprequest在表单提交上请求另一页面,我正在将该页面加载到span标签中。我的问题是我在被调用页面中有更多js,它会在点击文本框时加载日历。这个日历永远不会加载到我的页面中,但如果我在新窗口中通过
本身调用页面,javascript工作正常,任何想法?见下面
当你调用index并点击按钮时页面没有显示
提醒,当你直接调用getcall时,警报显示正常。
I am using AJAX XMLhttprequest to request another page on form submit
and I am loading that page into a span tag. My issue is that I have
more js in the called page that loads a calendar on click of a text
box. This calendar never loads in my page but if I call the page by
itself in a new window javascript works fine, any ideas? See Below
when you call index and click the button the page does not show the
alert, when you call getcall straight the alert shows fine.




通过innerHMTL插入脚本代码不会执行它(只有在NS6中才能执行

)。如果你想执行脚本代码,你将不得不单独加载它,使用createElement创建一个脚本块,然后

appendChild将该脚本块附加到任何现代浏览器都可以在

中执行一个节点。


-

Randy

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

暂时在: http:// members.aol.com/_ht_a/hikksnotathome/cljfaq/

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/



Inserting script code via innerHMTL won''t execute it (only in NS6 did
that work). If you want to execute script code, you are going to have to
load it separately, use createElement to create a script block, then
appendChild to append that script block to a node for it to execute in
any modern browser.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/




Randy Webb写道:

Randy Webb wrote:
通过innerHMTL插入脚本代码不会执行它(仅在NS6中确实有效)。如果你想执行脚本代码,你将不得不单独加载它,使用createElement创建一个脚本块,然后
appendChild将该脚本块附加到一个节点,以便它在<任何现代浏览器。

-
Randy
comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周
暂时在: http://members.aol。 com / _ht_a / hikksnotathome / cljfaq /
Javascript最佳实践 - http ://www.JavascriptToolbox.com/bestpractices/
Inserting script code via innerHMTL won''t execute it (only in NS6 did
that work). If you want to execute script code, you are going to have to
load it separately, use createElement to create a script block, then
appendChild to append that script block to a node for it to execute in
any modern browser.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/




Randy,我有没有办法用我正在传递的innerHTML来做这件事/>
而不是使用create元素?我在

调用页面中创建了一个日历对象,这根本不表现....我试图这样做

但它没有工作......


当我填充我使用的跨度....


result = http_request.responseText;

result = execJS(result);

document.getElementById(''call_results'')。innerHTML = result;


exec function ...

函数execJS(节点){

var st = node.getElementsByTagName(''SCRIPT'');

var strExec;

for(var i = 0; i< st.length; i ++){

strExec = st [i] .text;

try {

eval(strExec);

} catch(e){

alert(e);

}

}

}


它在getElementsByTagName上打嗝我知道为什么但是当我发出警报时我还能用什么来使用
节点字符串它具有我正在使用的所有页面

填充页面,但我无法让最后一块工作,我有

一直在读这个我在这种情况下可以使用eval函数 -
http://microformats.org/wiki/rest/ah...ing_Javascript


有什么想法吗?


在我写完上面之后我有了一个重大突破....


result = http_request.responseText;

document.getElementById(''call_results'')。innerHTML = result;

var d = call_results.getElementsByTagName(" script");

for(var x = 0; x< d.length; x ++){

with(window){

eval(d [x] .text);

}

}


像魅力一样工作。

right after I wrote the above I had a major breakthrough....

result = http_request.responseText;
document.getElementById(''call_results'').innerHTML = result;
var d=call_results.getElementsByTagName("script");
for(var x=0;x<d.length;x++) {
with(window) {
eval(d[x].text);
}
}

Works like a charm.


这篇关于AJAX问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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