473,471 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

AJAX Issue

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);
}

Jun 26 '06 #1
12 3097
wh****@gmail.com said the following on 6/26/2006 2:43 PM:
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.


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/
Jun 27 '06 #2

Randy Webb wrote:
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, is there a way I can do it with the innerHTML that I am passing
instead of using the create element? I create a calendar object in the
calling page and this is not behaving at all....I was trying to do this
but it was not working...

When I populate the span I am using....

result = http_request.responseText;
result = execJS(result);
document.getElementById('call_results').innerHTML = result;

exec function...
function execJS(node) {
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);
}
}
}

It hiccups on the getElementsByTagName I know why but what else can I
use, when i alert node string it has all of the page that I am using to
populate the page but I cannot get this final piece to work, I have
been reading that I can use the eval function in this case here -
http://microformats.org/wiki/rest/ah...ing_Javascript

Any ideas?

Jun 27 '06 #3
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.

Jun 27 '06 #4
wreed wrote:
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.


For now. I can just about guarantee that you will eventually encounter
problems because of using eval()

Any particular reason you don't want to do it the way Randy suggested,
which is the BEST way to handle it?
--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."
Jun 27 '06 #5
Tony wrote:

For now. I can just about guarantee that you will eventually encounter
problems because of using eval()

Any particular reason you don't want to do it the way Randy suggested,
which is the BEST way to handle it?
--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."


This is the js I have
<SCRIPT type="text/javascript" id="calendar_creation">
Calendar.setup({
inputField : "callback",
ifFormat : "%m/%d/%Y %I:%M %p",
showsTime : true,
weekNumbers : false,
timeFormat :"12"
});
</SCRIPT>

My js skills are lacking and I tried to create the element and append
the child element but it seemed to not work....thats why I did not
implement his.

Jun 27 '06 #6
wreed wrote:
Tony wrote:
For now. I can just about guarantee that you will eventually encounter
problems because of using eval()

Any particular reason you don't want to do it the way Randy suggested,
which is the BEST way to handle it?

This is the js I have
<SCRIPT type="text/javascript" id="calendar_creation">
Calendar.setup({
inputField : "callback",
ifFormat : "%m/%d/%Y %I:%M %p",
showsTime : true,
weekNumbers : false,
timeFormat :"12"
});
</SCRIPT>

My js skills are lacking and I tried to create the element and append
the child element but it seemed to not work....thats why I did not
implement his.


May I suggest that it would be better, then, to work on improving your
javascript skills?

What, exactly, did you do, and what happened? What did you do to track
down the problem? Did you do any research into using createElement for
dynamically adding javascript? (I happen to know there's plenty
available - this is something I just learned how to do about 6 months ago)

Frankly, I suspect you'll be more likely to get help if you are trying
to learn than you will if you dismiss the help offered because you don't
understand how to do it. Just my opinion, FWIW.

Post your attempts here - maybe you can work out what went wrong.

--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."
Jun 27 '06 #7
wreed said the following on 6/27/2006 10:54 AM:
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.


var d = call_results.getElementsByTagName("script")
for (var x=0;x<d.length;x++){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = d[x].text;
document.getElementById('call_results').appendChil d(newScript);
}
--
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/
Jun 27 '06 #8

Randy Webb wrote:

var d = call_results.getElementsByTagName("script")
for (var x=0;x<d.length;x++){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = d[x].text;
document.getElementById('call_results').appendChil d(newScript);
}
--
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/


I tried your code but it hangs my browser, I tried stepping through it
with interdev and I was able to but not sure why it hung up....

Can I ask what problems eval will cause me?

Jun 28 '06 #9
wreed wrote:
<snip>
Can I ask what problems eval will cause me?


As - eval - can do anything and everything that javascript can do it is
capable of causing all possible problems, with the additional problem
that errors originating with - eval - may be pinpointed to the - eval -
call responsible but they will not be explicit about the actual
error-producing code.

Richard.
Jun 29 '06 #10

Randy Webb wrote:
>
var d = call_results.getElementsByTagName("script")
for (var x=0;x<d.length;x++){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = d[x].text;
document.getElementById('call_results').appendChil d(newScript);
}
--
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 I ended up having to add an x = x + 1 to the for loop as it was
getting suck in an endless loop, not sure why x++ was not working in
the for syntax...but now I am using appendChild, curious in this case
its ok, but how do I deal with an onclick?

Jul 6 '06 #11
"wreed" <wh****@gmail.comwrites:
Randy Webb wrote:
>var d = call_results.getElementsByTagName("script")
for (var x=0;x<d.length;x++){
....
>document.getElementById('call_results').appendChi ld(newScript);
Randy I ended up having to add an x = x + 1 to the for loop as it was
getting suck in an endless loop, not sure why x++ was not working in
the for syntax...
The collection stored in the variable "d" is a live collection of
all script elements inside the "call_results" element. The loop
increments "x" until it reaches "d.length", but each loop also adds
another script element inside "call_results", so "d.length" is also
incremented, and the loop never ends.

By incrementing "x" twice, you do make the loop end, but you also
skip every other script element. Instead you could fix the end
point before starting the loop:

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

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 6 '06 #12
wreed said the following on 7/6/2006 4:01 PM:
Randy Webb wrote:
>var d = call_results.getElementsByTagName("script")
for (var x=0;x<d.length;x++){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = d[x].text;
document.getElementById('call_results').appendChi ld(newScript);
}
Randy I ended up having to add an x = x + 1 to the for loop as it was
getting suck in an endless loop, not sure why x++ was not working in
the for syntax...but now I am using appendChild, curious in this case
its ok, but how do I deal with an onclick?
One of two ways:

Method 1:
Define all your onclicks in a script block:

<script type="text/javascript">
document.getElementById('someElement').onclick = function(){....}
</script>

So that appendChild will execute it.

That would be the most reliable way to do it.

Method 2:

Try to parse the HTML string and dig out the on* event handlers and then
apply them yourself. That would get extremely messy before you ever got
started.
--
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/
Jul 8 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
4
by: ext237 | last post by:
Simple ajax call seems to have some issues in Firefox. The "onComplete:" is called BEFORE the response is returned by the call. Is there a coding issue or a work around? var ajax = new...
2
by: verci | last post by:
Hi guys, I'm running VS2005, AP.net 2.0, Windows XP SP2 Ok this maybe a dumb question but here it goes, as a newbie I've just finished my first AJAX enable page, everything works great but,...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
7
by: =?Utf-8?B?Tmlrb2xheSBFdnNlZXY=?= | last post by:
Hi! I know this topic has been discussed a long way, but I haven't found any apparent solution (maybe I shouldn't be looking for a one :)) I have a very simple application with one page and with...
10
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
5
by: simon | last post by:
hello, I have a server set up on my local (home) network and can not get an ajax application to run on the box. it works fine on our developement server and also works fine locally. I...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.