473,382 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Problem with AJAX calls in IE: function oes not receive returnedvalue after one time

Hello,
I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard.

The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.

I created a highly scaled down version of my page which demonstrates the problem. The page works in FF but not in IE7.

URL: http://samik.freeshell.org/test/ajaxtest.html

The backend perl is available at: http://samik.freeshell.org/test/ajaxTest.txt
Regards.
-Samik
May 31 '07 #1
8 3082
On 31 Mai, 07:10, "Samik R." <s...@frKKshKll.orgwrote:
Hello,
I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard.

The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.

I created a highly scaled down version of my page which demonstrates the problem. The page works in FF but not in IE7.

URL:http://samik.freeshell.org/test/ajaxtest.html

The backend perl is available at:http://samik.freeshell.org/test/ajaxTest.txt
Regards.
-Samik
Hi Samik,

i had the same problem some weeks ago. IE doesn't like javascript code
in onclick, onmouseover etc. inside dynamically added HTML content.
Maybe one solution is to add the onclick event after saving returned
HTML content is placed on the desired place. Another way is to use an
anchor tag where the javascript code is placed in the href attribute.
On this case IE won't be fussy and will accept your HTML output
including javascript code.
purcaholic

May 31 '07 #2
The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.

You are only creating the XMLHttpRequest once. You need a new
XMLHttpRequest object for each ajax request.

May 31 '07 #3
i had the same problem some weeks ago. IE doesn't like javascript code
in onclick, onmouseover etc. inside dynamically added HTML content.
Maybe one solution is to add the onclick event after saving returned
HTML content is placed on the desired place. Another way is to use an
anchor tag where the javascript code is placed in the href attribute.
On this case IE won't be fussy and will accept your HTML output
including javascript code.
In what way does IE not like onclick events? Can you provide sample
code?

May 31 '07 #4
Pete wrote:
>The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.


You are only creating the XMLHttpRequest once. You need a new
XMLHttpRequest object for each ajax request.
So, this is only true in IE, is it? FF does not seem to be having any problem !!
Thanks for your comment.
-Samik
May 31 '07 #5
purcaholic wrote:
On 31 Mai, 07:10, "Samik R." <s...@frKKshKll.orgwrote:
>Hello,
I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard.

The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.

I created a highly scaled down version of my page which demonstrates the problem. The page works in FF but not in IE7.

URL:http://samik.freeshell.org/test/ajaxtest.html

The backend perl is available at:http://samik.freeshell.org/test/ajaxTest.txt
Regards.
-Samik

Hi Samik,

i had the same problem some weeks ago. IE doesn't like javascript code
in onclick, onmouseover etc. inside dynamically added HTML content.
Maybe one solution is to add the onclick event after saving returned
HTML content is placed on the desired place. Another way is to use an
anchor tag where the javascript code is placed in the href attribute.
On this case IE won't be fussy and will accept your HTML output
including javascript code.
purcaholic
Thanks for your comment. I will try this, but I think my onClick event is working fine. The call to the perl program does get processed after the button is clicked, just that it does not return with the output.
May 31 '07 #6
On 31 Mai, 10:40, Pete <peter.gal...@gmail.comwrote:
i had the same problem some weeks ago. IE doesn't like javascript code
in onclick, onmouseover etc. inside dynamically added HTML content.
Maybe one solution is to add the onclick event after saving returned
HTML content is placed on the desired place. Another way is to use an
anchor tag where the javascript code is placed in the href attribute.
On this case IE won't be fussy and will accept your HTML output
including javascript code.

In what way does IE not like onclick events? Can you provide sample
code?
I have had this behavior few weeks ago. It wasn't possible to use any
javascript code inside a onclick attribute. Have tested it today with
another code snippets ant it works also on IE, can't reproduce the
issue. Maybe i had an specific error, depending on environment
settings.

The first error was something like "invalid character at postition
xy", even though valid encoding. After than IE didn't respond to any
javascript code in onclick attribute. Could solve this issue after
moving everything from onclick to href attribute.

May 31 '07 #7
On 31 Mai, 15:32, "Samik R." <s...@frKKshKll.orgwrote:
purcaholic wrote:
On 31 Mai, 07:10, "Samik R." <s...@frKKshKll.orgwrote:
Hello,
I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard.
The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.
I created a highly scaled down version of my page which demonstrates the problem. The page works in FF but not in IE7.
URL:http://samik.freeshell.org/test/ajaxtest.html
The backend perl is available at:http://samik.freeshell.org/test/ajaxTest.txt
Regards.
-Samik
Hi Samik,
i had the same problem some weeks ago. IE doesn't like javascript code
in onclick, onmouseover etc. inside dynamically added HTML content.
Maybe one solution is to add the onclick event after saving returned
HTML content is placed on the desired place. Another way is to use an
anchor tag where the javascript code is placed in the href attribute.
On this case IE won't be fussy and will accept your HTML output
including javascript code.
purcaholic

Thanks for your comment. I will try this, but I think my onClick event is working fine. The call to the perl program does get processed after the button is clicked, just that it does not return with the output.- Zitierten Text ausblenden -

- Zitierten Text anzeigen -
Excuse me for my wrong answer, IE works fine with dynamically added
content by ajax including onclick attributes.

You should create, as Pete wrote before, a new XMLHttpRequest on each
request. Cjhange youre code as follows:
[snip]
....
var AjaxRequester=null;
function setNewAjaxRequester(){
if(window.ActiveXObject)
{ AjaxRequester = new ActiveXObject("Microsoft.XMLHTTP"); }
else if(window.XMLHttpRequest)
{ AjaxRequester = new XMLHttpRequest(); }
}
....
// This method does the heavy lifting of calling AJAX and displaying
data
function display(TargetDivName,Var,Val)
{
//Call this to create a new XMLHttpRequest object
setNewAjaxRequester();
// Get the target div element
TargetDiv=document.getElementById(TargetDivName);
....
}
....
[/snap]

Then the "javascript" string is only for usage in href attribute
(href="javascript:alert('foo')"), it's not necessary in onclick,
because content of onclick attribute will allways handled as
javascript code.
The code onClick="display('CredBody','TeamLogin','Team1');" will also
do the job.
purcaholic

May 31 '07 #8
purcaholic wrote:
On 31 Mai, 15:32, "Samik R." <s...@frKKshKll.orgwrote:
>purcaholic wrote:
>>On 31 Mai, 07:10, "Samik R." <s...@frKKshKll.orgwrote:
Hello,
I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard.
The problem is, this works perfectly as expected in FF (2.0). In IE (7.0) however, the first time I press the button, the things are fine and the second button comes in. Pressing this button does not do anything, although the perl routine does get called and the return HTML gets generated. Somehow the HTML never reaches the browser or something similar. The JS stateChangeHandler method for the XMLHTTP object, which should handle things when readyState changes to 4 and status changes to 200 etc. never gets fired.
I created a highly scaled down version of my page which demonstrates the problem. The page works in FF but not in IE7.
URL:http://samik.freeshell.org/test/ajaxtest.html
The backend perl is available at:http://samik.freeshell.org/test/ajaxTest.txt
Regards.
-Samik
Hi Samik,
i had the same problem some weeks ago. IE doesn't like javascript code
in onclick, onmouseover etc. inside dynamically added HTML content.
Maybe one solution is to add the onclick event after saving returned
HTML content is placed on the desired place. Another way is to use an
anchor tag where the javascript code is placed in the href attribute.
On this case IE won't be fussy and will accept your HTML output
including javascript code.
purcaholic
Thanks for your comment. I will try this, but I think my onClick event is working fine. The call to the perl program does get processed after the button is clicked, just that it does not return with the output.- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Excuse me for my wrong answer, IE works fine with dynamically added
content by ajax including onclick attributes.

You should create, as Pete wrote before, a new XMLHttpRequest on each
request. Cjhange youre code as follows:
[snip]
...
var AjaxRequester=null;
function setNewAjaxRequester(){
if(window.ActiveXObject)
{ AjaxRequester = new ActiveXObject("Microsoft.XMLHTTP"); }
else if(window.XMLHttpRequest)
{ AjaxRequester = new XMLHttpRequest(); }
}
...
// This method does the heavy lifting of calling AJAX and displaying
data
function display(TargetDivName,Var,Val)
{
//Call this to create a new XMLHttpRequest object
setNewAjaxRequester();
// Get the target div element
TargetDiv=document.getElementById(TargetDivName);
...
}
...
[/snap]

Then the "javascript" string is only for usage in href attribute
(href="javascript:alert('foo')"), it's not necessary in onclick,
because content of onclick attribute will allways handled as
javascript code.
The code onClick="display('CredBody','TeamLogin','Team1');" will also
do the job.
purcaholic
I found out a workaround, which is pretty well documented. I had to reverse the order of XHR.open and XHR.onreadystatechange. Following webpage is a good source:
http://keelypavan.blogspot.com/2006/...ect-in-ie.html

Thanks.
-Samik
Jun 1 '07 #9

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

Similar topics

10
by: CES | last post by:
All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon...
0
by: raza | last post by:
Hi, I have been programmin in C# for quite some time now and recently got into sockets programming in C# though i have done it in C++ on windows/linux . I have an interesting problem at hand . ...
2
by: Max | last post by:
Please, could anyone tell me, how can I call directly the function in vb script after I registered it with RegisterClientScriptBlock? thanks Ma
42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
3
by: dhsieh | last post by:
I am trying out nested AJAX calls for the first time, but I seem to have hit a snag. The code snippet is the outer AJAX call and a function, it gathers information about a company. As we get towards...
5
by: Eyeinstyin | last post by:
Basic Problem is Every scroll of scrollbar makes an ajax call.So if user play with scrollbar say 100 times 100 ajax calls go and server starts processing 100 calls.So abort won't help.The last time...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.