473,829 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

html snippet returned by xmlhttprequest. responseText displayed as text

This is my code

function getDetails()
{
var name = document.getEle mentById("movie _name").value;

if (window.XMLHttp Request) //For Mozilla Browsers
{
XMLHttp=new XMLHttpRequest( )
}
else if (window.ActiveX Object) // For Microsoft Browsers
{
XMLHttp=new ActiveXObject(' Microsoft.XMLHT TP')
}

var
url="http://localhost/WebService1/Service.asmx/GetMovieByName" ;
var params="name=" + name;

XMLHttp.open("P OST",url,true) ;

XMLHttp.setRequ estHeader('Cont ent-Type','applicat ion/x-www-form-urlencoded');
XMLHttp.setRequ estHeader("Cont ent-Length", params.length)
XMLHttp.onready statechange=sta teChanged ;

XMLHttp.send(pa rams);
}

function stateChanged()
{
if (XMLHttp.readyS tate==4 || XMLHttp.readySt ate=="complete" )
{

var v = document.getEle mentById("respo nseDiv");
v.innerHTML = XMLHttp.respons eText;
}
}

and there a division like

<div id="responseDiv " align=center>
</div>

below in the page.
Now i have checked that my webservice returns the proper html snippet
as string and that the XMLHttp.respons eText contains proper html
snippet(a table). But it is displayed as text . The html is correctly
displayed but i want it to show the table rather than the html code?

Can anybody help me out.

Thanks

Dec 12 '06 #1
6 7819
mi*********@gma il.com wrote:
var v = document.getEle mentById("respo nseDiv");
v.innerHTML = XMLHttp.respons eText;
Now i have checked that my webservice returns the proper html snippet
as string and that the XMLHttp.respons eText contains proper html
snippet(a table).
How did you check that exactly? Which user agents have you tried?
Setting innerHTML parses the string you set to as HTML so I don't think
what you describe is possible. You are either setting innerText (or
textContent) instead of innerHTML or the responseText contains escaped
HTML markup (e.g. &lt;table&gt ; instead of <table>).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 12 '06 #2
Thanks Martin, but here's how i did it.
My webservice gets me the data in the form of XML and i parse that XML
on the serverside using XSLT and convert it to HTML and return the html
in a string variable. While Debuggin the webservice i checked that the
HTML is something like <table>...... .</table and not
&lt;table&gt ; as you thought it would be.

So when i press the button....the division gets painted by the
following text........... ..
<table>...
.....
.....
......</table>.

I dont understand whats going on. And i have double checked it taht i
am settig the innerHTML property.

See if you can tell me smth more on this.
Thanks again
Martin Honnen wrote:
mi*********@gma il.com wrote:
var v = document.getEle mentById("respo nseDiv");
v.innerHTML = XMLHttp.respons eText;

Now i have checked that my webservice returns the proper html snippet
as string and that the XMLHttp.respons eText contains proper html
snippet(a table).

How did you check that exactly? Which user agents have you tried?
Setting innerHTML parses the string you set to as HTML so I don't think
what you describe is possible. You are either setting innerText (or
textContent) instead of innerHTML or the responseText contains escaped
HTML markup (e.g. &lt;table&gt ; instead of <table>).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 12 '06 #3
Hey Martin,

you were right, I later rechecked that the webservice returns a string
something like.......

<table>...... </table>

which is reciebed on the client side as
&lt;table&gt;.. ....&lt;/table&gt;

so it is displayed as text. Can you tell me how to solve this problem?

Martin Honnen wrote:
mi*********@gma il.com wrote:
var v = document.getEle mentById("respo nseDiv");
v.innerHTML = XMLHttp.respons eText;

Now i have checked that my webservice returns the proper html snippet
as string and that the XMLHttp.respons eText contains proper html
snippet(a table).

How did you check that exactly? Which user agents have you tried?
Setting innerHTML parses the string you set to as HTML so I don't think
what you describe is possible. You are either setting innerText (or
textContent) instead of innerHTML or the responseText contains escaped
HTML markup (e.g. &lt;table&gt ; instead of <table>).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 13 '06 #4
Hey Martin,

You were right. I put an alert(XMLHttpre quest.responseT ext) and the
alert shows me the html returned by the webservice in the form of
escaped markup as you had said. so its displays the html code. rather
than the table that i expect it to display.

So now what should i do if i want to get the table displayed?

Thanks

mi*********@gma il.com wrote:
Thanks Martin, but here's how i did it.
My webservice gets me the data in the form of XML and i parse that XML
on the serverside using XSLT and convert it to HTML and return the html
in a string variable. While Debuggin the webservice i checked that the
HTML is something like <table>...... .</table and not
&lt;table&gt ; as you thought it would be.

So when i press the button....the division gets painted by the
following text........... ..
<table>...
....
....
.....</table>.

I dont understand whats going on. And i have double checked it taht i
am settig the innerHTML property.

See if you can tell me smth more on this.
Thanks again
Martin Honnen wrote:
mi*********@gma il.com wrote:
var v = document.getEle mentById("respo nseDiv");
v.innerHTML = XMLHttp.respons eText;
Now i have checked that my webservice returns the proper html snippet
as string and that the XMLHttp.respons eText contains proper html
snippet(a table).
How did you check that exactly? Which user agents have you tried?
Setting innerHTML parses the string you set to as HTML so I don't think
what you describe is possible. You are either setting innerText (or
textContent) instead of innerHTML or the responseText contains escaped
HTML markup (e.g. &lt;table&gt ; instead of <table>).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 13 '06 #5
mi*********@gma il.com wrote:
You were right. I put an alert(XMLHttpre quest.responseT ext) and the
alert shows me the html returned by the webservice in the form of
escaped markup as you had said. so its displays the html code. rather
than the table that i expect it to display.

So now what should i do if i want to get the table displayed?
Have you considered changing the web service to return XML? Or if you
want to return HTML markup that is not well-formed XML then at least
change the web service to send the HTML as plain text and not escaped.

Other than that you can only do what you have tried e.g.
var div = document.create Element('div');
div.innerHTML = XMLHttp.respons eText;
v.innerHTML = div.innerText;

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 13 '06 #6
Thanks Martin,

But
I AM returning a html as normal text from the webservice.
something like this........

string str = <b>Hello there!!!!</b //Actually the html is generated
by xslt from an xml doc
return str;

while debugging i have checked taht the contents of str
are normal text like "<b>Hello there!!!!</b "

and on the client side there's an javascript alert like

alert(XMLHttpre quest.responseT ext);

which shows some XML headers like <?xml version"1" encoding="UTF8" >
etc etc
and then

&lt;b&gt;Hel lo there!!!&lt;/b&gt;

I'll see if i have some other function with respect to responseXML on
the client side

Thanks

Martin Honnen wrote:
mi*********@gma il.com wrote:
You were right. I put an alert(XMLHttpre quest.responseT ext) and the
alert shows me the html returned by the webservice in the form of
escaped markup as you had said. so its displays the html code. rather
than the table that i expect it to display.

So now what should i do if i want to get the table displayed?

Have you considered changing the web service to return XML? Or if you
want to return HTML markup that is not well-formed XML then at least
change the web service to send the HTML as plain text and not escaped.

Other than that you can only do what you have tried e.g.
var div = document.create Element('div');
div.innerHTML = XMLHttp.respons eText;
v.innerHTML = div.innerText;

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 14 '06 #7

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

Similar topics

2
3184
by: alex bazan | last post by:
I've got this piece of code that imports an XML document ... it works for both mozilla and IE. function getXMl(url) { if (!document.all) { var xmlDoc = document.implementation.createDocument('','doc',null); var xmlHTTP = new XMLHttpRequest(); xmlHTTP.overrideMimeType("text/xml"); xmlHTTP.open("GET",url, false);
2
2227
by: Arun | last post by:
I am trying to build a site using xmlhttprequest, so that the browser never reloads. I want to pass the HTML info of the "navigation column" , "content column" as a XML page from the server. >From the help on the net, I have managed to use xmlhhtprequest succesfully to get the file from server and parse the XML. But I dont know how to display the HTML info on the page. When I just add the parsed HTML content from the xml to a <div>, it...
10
5382
by: Tony | last post by:
I'm wondering if anyone has run any tests to compare the speed of parsing XML vs text in simple lists - such as: <?xml version="1.0" encoding="ISO-8859-1"?> <users> <user>User 1</user> <user>User 2</user> <user>User 3</user> </users>
1
1517
by: mauroalberti | last post by:
Hello everyone, I'm currently trying to add some AJAX functionality to the tree2 JSF-component from the Apache MyFaces project (i. e. if the user clicks on some node of the tree component, then not the whole tree is to be rendered again but just the part of the tree which has actually changed). Using Mozilla as browser everything works fine, but if IE is used I'm facing the following problem:
9
2162
by: Phil_Harvey | last post by:
I am redoing my website and trying to get it to do something more exciting using Javascript. I did normal Java at university and code at work in VB.NET. I have got reasonably far into what I want to do but am having some issues. Firstly I am using an XmlHttpRequest to pull html fragments out of files and wish to put them into the main doccument inplace of a <span></span> which has a given id. The user enters a "command" into a TextField...
7
3643
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it simple and schematic, to see if there is a simple Ajax answer to this. A. I have an HTML page which has some pure html/css code representing a GRID of cell. The page may also contain other objects (images, etc). B. On the server I have a windows...
20
4062
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great and populates into the webpage; however, executing javascript has a few problems: 1. Opens on a blank page, but not a new page. It appears to compeltely overwrite the original page. I want it to update the existing page by loading within a <div>...
1
1621
by: Duke | last post by:
<html> <head> <script type="text/javascript"> function init(){ var html = document.open('Hello.html'); document.getElementById } </script> <body onload ="init();"> <did = 'hi'>
5
4471
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php script works perfectly and gives me an entire table of correct data. The problem is that when I click...
0
9632
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10471
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
10510
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
10189
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
9296
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
7732
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
5612
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
5771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3951
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.