473,804 Members | 3,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 stateChangeHand ler 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 3120
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 stateChangeHand ler 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 stateChangeHand ler 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 stateChangeHand ler 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 stateChangeHand ler 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...@g mail.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 stateChangeHand ler 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=n ull;
function setNewAjaxReque ster(){
if(window.Activ eXObject)
{ AjaxRequester = new ActiveXObject(" Microsoft.XMLHT TP"); }
else if(window.XMLHt tpRequest)
{ AjaxRequester = new XMLHttpRequest( ); }
}
....
// This method does the heavy lifting of calling AJAX and displaying
data
function display(TargetD ivName,Var,Val)
{
//Call this to create a new XMLHttpRequest object
setNewAjaxReque ster();
// Get the target div element
TargetDiv=docum ent.getElementB yId(TargetDivNa me);
....
}
....
[/snap]

Then the "javascript " string is only for usage in href attribute
(href="javascri pt:alert('foo') "), it's not necessary in onclick,
because content of onclick attribute will allways handled as
javascript code.
The code onClick="displa y('CredBody','T eamLogin','Team 1');" 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 stateChangeHand ler 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=n ull;
function setNewAjaxReque ster(){
if(window.Activ eXObject)
{ AjaxRequester = new ActiveXObject(" Microsoft.XMLHT TP"); }
else if(window.XMLHt tpRequest)
{ AjaxRequester = new XMLHttpRequest( ); }
}
...
// This method does the heavy lifting of calling AJAX and displaying
data
function display(TargetD ivName,Var,Val)
{
//Call this to create a new XMLHttpRequest object
setNewAjaxReque ster();
// Get the target div element
TargetDiv=docum ent.getElementB yId(TargetDivNa me);
...
}
...
[/snap]

Then the "javascript " string is only for usage in href attribute
(href="javascri pt:alert('foo') "), it's not necessary in onclick,
because content of onclick attribute will allways handled as
javascript code.
The code onClick="displa y('CredBody','T eamLogin','Team 1');" 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.onreadystat echange. 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
6725
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 exiting a form field, if the
0
1264
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 . I am porting a C++ tunnel library into C# . It has 2 functions WriteOut: I make a header and send it then send the actual data to the server and it calls Write function
2
353
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
34251
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.07/Linux, Firefox 1.5/Linux, Firefox 1.5/Windows and Firefox 1.5/Mac, Safari/Mac. It works perfectly on a lot of configurations but, on some PC with Firefox 1.5/Windows (not all), the Javascript code with XmlHttpRequest
1
4036
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 technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
2
3174
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 i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
3
3956
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 the bottom of the onComplete function, there is a call to doGetAddressContacts(), which accepts an address ID. This then returns a list of contacts at that address. What I am trying to do is for each address that it retrieves and outputs, as it...
5
2345
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 the scroll bar has stopped scrolling(say for 1000 millisecond),ajax call should go.My function uses object function call.So how can i use setTimeOut() My function looks likes this temp contain xmlHTpp object var temp=new xmlHttpObject(); ...
8
3146
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" post. Third, there are pieces of this code that I am not at liberty to display, change, discuss, or re-implement. As far as this question is concerned, this means that (1) I cannot use 3rd party libraries, which is why I've implemented my own...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.