473,732 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX (IE 6.0) responseText partially disappear?

88 New Member
I hate to bug you guys with more of my problems but IE is trying to make me climb my walls for the past several hours...

I thought I just explain the problem and if it sounds familiar I could get some clues on what to search for.

I haved used a simple XhttpRequest, POST method, for a good while now, and it worked fine both in IE and FF.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function XR( uses POST ) // called form ajax.js
  3.  
  4. document.onchange = function(){ does stuff, then calls XR and sends data back to database; database returns a string containing basic html  } // called from sendStuff.js
Now I wanted to use the same XR function again in another function, on the same page:

Expand|Select|Wrap|Line Numbers
  1. function A() { does some stuff, then calls XR and sends more stuff back to database; database returns a string containing basic html  
The html string is returned as a js var and is eval'd, which js then picks up and prints out.

All functions are run on the same page.

The first function (the anonymous one) works in all browsers IE, FF and Opera. And all is good. The second function however only works in FF and Opera; IE is giving me some weird vibes.

I've used bugzilla, venkman and operas debugger, but none of them gave any error messages, and I don't know where to look besides that.

IE debugger higlights three instances in the code and tells me that an unexpected error has occured etc, but it doesn't provide any further (useful) information. I have however "pin pointed" the problem down to the last line in the second function, and it is one of the weirdest problems I have encountered hitherto.

The two variables that are passed back from PHP to the JS are safely returned. One of them however is, how should I put it, twisted and turned to something evil; the second variable is suppose to be something like this:

[HTML]
<element1>
<element2>
<element3>(...) </element3>
<element3>(...) </element3>
<element3>(...) </element3>
</element2>
</element1>
[/HTML]

But only element 1 and 2 are returned ??? !!! I don't get it?! Why?

And why can't explorer print that as is? Why does it respond with a fatal error?

I'm going nuts over here... Why doesn't FF and Opera, or Venkman tell me anything?

Forgot: the error occurs when the god forsaken js var (which contains basic html elements) is trying to replace the innerHTML of another element on the page.
May 17 '08 #1
8 2568
acoder
16,027 Recognized Expert Moderator MVP
Can you show the code and how/when it's called or a test link, if possible?
May 17 '08 #2
ManWithNoName
88 New Member
(thanks for your reply :D)

Here is the code:

The XhttpRequestObj ect loader

Expand|Select|Wrap|Line Numbers
  1. function XhttpRequest() {
  2.   var XhttpRequestObject=null;
  3.     try { // FIREFOX | OPERA 8.0+ | SAFARI
  4.       XhttpRequestObject=new XMLHttpRequest();
  5.     }
  6.     catch (e) { // INTERNET EXPLORE
  7.       try {
  8.         XhttpRequestObject=new ActiveXObject('Msxml2.XMLHTTP');
  9.       }
  10.       catch (e) {
  11.         try {
  12.           XhttpRequestObject=new ActiveXObject('Microsoft.XMLHTTP');
  13.         }
  14.         catch (e) {
  15.           alert('error');
  16.           return false;
  17.         }
  18.       }
  19.     }
  20.     return XhttpRequestObject;
  21. }
  22.  
  23.  
The XhttpRequest fn

Expand|Select|Wrap|Line Numbers
  1. function XhttpRequestPHP(POST){
  2.   var XhttpRequestObject=new XhttpRequest();
  3.   XhttpRequestObject.open('POST','/ajax.php',true);
  4.   XhttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  5.   XhttpRequestObject.setRequestHeader("Content-length",POST.length);
  6.   XhttpRequestObject.send(POST);
  7.  
  8.   XhttpRequestObject.onreadystatechange = function() { 
  9.     switch(XhttpRequestObject.readyState) {
  10.       case 0: // REQUEST NOT INITIALIZED
  11.         alert('error');
  12.         return false;
  13.         break;
  14.       case 1: // REQUEST HAS BEEN SET UP
  15.         break;
  16.       case 2: // REQUEST HAS BEEN SENT
  17.         break;
  18.       case 3: // REQUEST IS IN PROCESS
  19.         break;
  20.       case 4: // REQUEST IS COMPLETE
  21.         window.eval(XhttpRequestObject.responseText);
  22.         document.getElementById(ElementId).innerHTML = CallbackString ;
  23.         break;
  24.     }
  25.   } 
  26. }
  27.  
The function that works

Expand|Select|Wrap|Line Numbers
  1.  
  2. document."onevent" = function(e){
  3.   // event handler; nothing fancy
  4.   // when event
  5.   XhttpRequestPHP('the string to be posted to php');
  6. }
  7.  
  8.  
The functions is called when the user clicks on a button. This functionen is not embedded in the html code (and that is why I have a event handler)
I get a back a very complex html element node set, no problems at all.

The function that gives me a problem

Expand|Select|Wrap|Line Numbers
  1.  
  2. function B(ThisObject){
  3.   // do stuff with "this"; extract values etc; nothing fancy
  4.   // post values back as string
  5.   XhttpRequestPHP('the string to be posted to php');        
  6. }
  7.  
  8.  
The functions is also called when the user clicks on a button. This function is however embedded in the html (<button onclick="B(this ); />")

This function makes IE throw an error at "document.getEl ementById(Eleme ntId).innerHTML = CallbackString; "

However, when I use the MS debugger "command window" and type "alert(ElementI d)" or "alert(Callback String)" I do get a sucessful answer... Sort of; In the IE window I get the CallbackString alerted it is however only partially returned, and in the IE debugger "command window" I get an "undefined" reponse... So...

An interesting note that I didn't understand, but I know think may have something to do with this: in the MS debugger when it throws an error there is a window called "call stack" and it says (the heading) "running thread (000000A1C) and beneath it is an item: "<JScript> - JScript anonymous function", is it saying that the functions are colliding? 'Cause that would make sense, sort of... I still get the error if I remove the first function...

The only difference between those two functions are otherwise that one is runned anonymously and the other is not...

My head hurts...
May 18 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Why can't you return the HTML text only from the PHP script instead of a string which has to be eval'd? If responseText contains HTML, you can set it directly to the element using innerHTML.
May 18 '08 #4
ManWithNoName
88 New Member
Why can't you return the HTML text only from the PHP script instead of a string which has to be eval'd? If responseText contains HTML, you can set it directly to the element using innerHTML.
Thanks for your reply;
if I understand you correctly, I'd say that, the reason I do as I do is because:
sometimes I need to change the content of two elements simultaneously, and then I need to send them back as two different variables. The only reason it needs to eval is because the variables need to be activated as JS var.

But that shouldn't cause any problems. When I

Expand|Select|Wrap|Line Numbers
  1. alert(XhttpRequestObject.status); // returns 200
  2. alert(XhttpRequestObject.statusText); // returns OK
  3. alert(XhttpRequestObject.responseText); // returns the partiall html code, i.e. the same code as when "eval'd"
  4.  
  5.  
If you mean why I don't do this "return XhttpRequestObj ect.responseTex t", then call it like "var a = XhttpRequestPHP (POST)", I'd have to say that I can't... The result will be "undefined"

I believe the error is either because I run two XhttpRequest functions at the same time, or because the second XhttpRequest is called within a static (declared) function.

Now, I'm no JS expert, but that's the only logical conclusion I can draw, no?

Can't I run my XhttpRequestPHP function as "new XhttpRequestPHP ()"? Is this relevent?

I'm sorry if my conclusion sounds stupid, but I haven't had any time to learn much JS (more advanced stuff anyway).
May 18 '08 #5
ManWithNoName
88 New Member
I fixed the problem with the "partiall response text"...

It seems that IE (6.0) doesn't accept the html '<button type="submit">I thought I was a button until IE told me otherwise</button>'-tag; you have to use '<input type="submit" value="I am a button" name="button"/>'

I do believe this is a IE 6.0 bug, or "rendering incompetence".

Anyway, the AJAX response is however the same, it refuses to populatet the innerHTML on response... :(

That shuld leave my previous conclusion still valid: the error is because
  1. two XhttpRequest functions are run at the same time/page, or
  2. the second XhttpRequest is called within a static (declared) function.

Is the answer to this question that I should run my second function as "new XhttpRequestPHP ()"?

Please I'm so close to eternal happiness; prove Buddha wrong, help me.
May 18 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
if I understand you correctly, I'd say that, the reason I do as I do is because:
sometimes I need to change the content of two elements simultaneously, and then I need to send them back as two different variables.
In which case, parse the response. Use a delimiting character and split using the split() method.

I believe the error is either because I run two XhttpRequest functions at the same time
This is probably the cause of the problem. Use a different variable for each request.
May 18 '08 #7
ManWithNoName
88 New Member
I found the solution... And it had nothing to do with AJAX--go figure.

http://domscripting.com/blog/display/99

It seems that there is a[nother] bug in IE regarding how it handles innerHTML.

You got to love the irony: one of the most popular self-defined functions created by Microsoft which they themselves can't implement properly.

Anyway, I appreciate the time you put down in trying to help me, thanks!

PS. I'm sticking with eval() ;p
May 18 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
A bug in IE6?! Well, I never... ;)

Thanks for posting the solution.
May 19 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
14564
by: Jean-Philippe Encausse | last post by:
Hi, I got 2 bugs using AJAX with ISO-8859-1: 1. While serializing form's value using prototype.js I lost accent éàè ... because it use encodeURIComponent() function. I saw on google, for ISO-8859-1 encoding I have to use escape(). It works fine ! 2. While receving content from AJAX Request with header <?xml
4
4326
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 from within an inline function. Within the AJAX object: this.xmlhttp = new XMLHttpRequest(); this.response = ''; //to contain the response text OR xml var that = this; //since we cannot reference this within the
1
4032
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
17
11882
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition show
6
5165
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and seemed not to fire until after the long running process had completed. I found the only real...
1
1833
by: shiniskumar | last post by:
i go tto perform some validation while ck=liking a button without refreshing the value.. i used ajax.My code is as follows...on button click i call the function validateGridAdd(); Inside tat function i need to call the function tat uses ajax to go to the server and come back.. the resultant value is to be obtained in the main function validateGridAdd(). //main function function validateGridAdd(a,rowNum){ var tForm =...
3
2077
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes several Ajax.Request calls to gather data from the server. What I'm having trouble with is getting the data from the Ajax call back to the custom class instance. I basicially want to get a Javascript array from my PHP page and insert that into the...
2
4677
by: mndprasad | last post by:
Hi friends, Am new to AJAX coding, In my program am going to have two texbox which going to implent AJAX from same table. One box is going to retrieve the value of other and vice versa. I have implemented successfully for one text box, but it's done for the other field, since am getting script errors. <script> var queryField; var lookupURL; var divName;
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
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
9235
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
8186
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...
1
6735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
3
2180
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.