PDA

View Full Version : loading html in DIV tag



ravimmrk
05-26-2008, 10:47 AM
i am trying to load a html page in div.. its working fine in local machine, but when i upload to server its working fine in IE7 , but its not working in IE6 what would be problem.. below given is the script i am using...

Please help me in solving the issue.. i Need to deliver the product today help me to solve the issue.. thanks in advance.. ravimmrk@gmail.com


function loadXmlHttp(url, id) {
var f = this;
f.xmlHttp = null;

if (window.XMLHttpRequest&&!f.ie||/^http/.test(window.location.href))
f.xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari, others, IE 7+ when live - this is the standard method
else if (/(object)|(function)/.test(typeof createRequest))
f.xmlHttp = createRequest(); // ICEBrowser, perhaps others
else {
f.xmlHttp = null;


}
if(f.xmlHttp != null){
f.el = document.getElementById(id);
f.xmlHttp.open("GET",url,true);
f.xmlHttp.onreadystatechange = function(){f.stateChanged();};
f.xmlHttp.send(null);
}

else alert('Your browser does not support AJAX!'); // substitute your desired request object unsupported code here
}
loadXmlHttp.prototype.stateChanged=function () {
if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !/^http/.test(window.location.href)))
this.el.innerHTML = this.xmlHttp.responseText;

}

function loadpage (url, id){

new loadXmlHttp(url, id)

}

jscheuer1
05-27-2008, 02:59 PM
I don't know for sure where you got that code, but it looks like it came from:

http://www.dynamicdrive.com/forums/showthread.php?p=143849#post143849

If so (or even if you got it elsewhere), you aren't playing with a full deck, use the full code. Also, if the IE 6 that you are testing in is a 'stand alone' version of IE 6, even if it is not, it may have key elements in it disabled, thus not allowing it to perform a request.

molendijk
05-27-2008, 06:38 PM
I don't know for sure where you got that code, but it looks like it came from:

http://www.dynamicdrive.com/forums/showthread.php?p=143849#post143849


Nice script. However, when my external URL contains foreign characters (like 'thé'), I get 'th?'. This is a general ajax-problem that I cannot solve.
---
Arie.

jscheuer1
05-28-2008, 04:22 PM
Nice script. However, when my external URL contains foreign characters (like 'thé'), I get 'th?'. This is a general ajax-problem that I cannot solve.
---
Arie.

I'm not positive I understand, at first I thought you meant the URL, in which case you could just escape it or URLencode it. But after rereading your post, I think you mean characters on the external page. For that, you must make sure that the server is serving the page with the proper Content-Type charset. Most default to UTF-8 for AJAX requests regardless of any meta-tag on the external page. However the server itself may be configured to use iso-8859-1 or whatever is required. The .htaccess file may be used for this, as can the server's main configuration panel. I don't have the specifics on either, but you can Google how this is done with .htaccess (requires authorization and capability), and how a particular server can be configured in its panel would vary somewhat from server to server.

Although, for just a few characters on a page, you may be able to use their entities, like:


é

for é.

molendijk
05-28-2008, 05:51 PM
Thanks John,
Yes, I know about the entities corresponding to the foreign characters. But that solution requires too much 'extra work' in certain cases.
As for the server's configuration: I'm trying to solve this matter for a friend who doesn't have access to it (his site is a hosted one).
The easiest solution would be a script that automatically replaces the foreign characters with the corresponding entities in the external page, I guess.
The strange thing is that the problem does not arise when we use a java-based script like the following (but that doesn't work in IE):
<SCRIPT type="text/javascript">
var data = new Array();
var i = 0;
var datafile = window.location.href.substring(0,
window.location.href.lastIndexOf("/") + 1) + "test.html";
var url = new java.net.URL(datafile);
var connect = url.openConnection();
var input = new java.io.BufferedReader(
new java.io.InputStreamReader(
connect.getInputStream()));
var aLine = ""
while((aLine = input.readLine())!= null) {
data[i++] = aLine;
}
</SCRIPT>

<SCRIPT type = "text/javascript">
var temp = ""
for (var j = 0; j < data.length ; j++)
temp += data[j] + "<br>";
document.write(temp);
</SCRIPT> .
---
Arie.

jscheuer1
05-28-2008, 07:09 PM
Another possibility would be, if the server has PHP or asp, to put a Content-Type charset header on the page in that language (PHP or asp) and rename it to .php or .asp - I know that this can be done with PHP, not sure about asp - though the two can usually do the same (basic) things as each other, it's just the syntax that varies.

I don't know anything (much) about java, but wouldn't that require a java plug in? If so, the way to create a java object in IE is with ActiveX (not sure of the exact syntax), so you would have to test and branch for that most likely to get your java code to execute in IE.

molendijk
05-28-2008, 07:33 PM
Non-IE browsers have exposed the JAVA objects java and Packages. That's why the above script works in those browsers. IE doesn't have that functionality. It creates java in its own way using ActiveX.
Anyhow, I think I might be able to solve the problem using a replace-function for foreign characters. I'm working on it. I'll let you know. Thanks so far.
===
Arie.