473,385 Members | 1,736 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,385 software developers and data experts.

Receive an html code to paste it in a table with Ajax


Hi

I'm new to Ajax but I've used javascript from time to time.

Now, I've a java application that will generate a page with data in a
table. I want to make a link in each row so when user click it, connect
to my server and get some more data to fill a hidden row below the
clicked one.

I guess it could be simple and could imagine that somebody could have
some code in that way and, may be, would like to share it... or just
give me a clue about how to do it.

I've been googling for this but every thing I found is about xml data
but I think it could be possible to retrieve just xhtml portions of
code with ajax/javascript...

Any help appreciated...

Thanks in advance

C

Jan 18 '07 #1
5 1516
ASM
Cacho a écrit :
Hi

I'm new to Ajax but I've used javascript from time to time.

Now, I've a java application that will generate a page with data in a
table. I want to make a link in each row so when user click it, connect
to my server and get some more data to fill a hidden row below the
clicked one.

I guess it could be simple
Not really ...
and could imagine that somebody could have
some code in that way and, may be, would like to share it... or just
give me a clue about how to do it.
To know on witch row (index of row) you are when you click.
To call via XMLHttpRequest the file to display.
To know in which cell of next row (index+1) you want to inner what was
received.
I've been googling for this but every thing I found is about xml data
but I think it could be possible to retrieve just xhtml portions of
code with ajax/javascript...
You mean you want to get a large file via XMLHttpRequest, then to insert
in next row only a little part of what was received ?

<script type="text/css">

var rangs, cible, http_request=false;

onload = function() {

// rangs = collection of rows -- cible = main target
var rangs = document.getElementById('myTable');
var cible = rangs.getElementsByTagName('TBODY')[0];
rangs = cible.getElementsByTagName('TR');

// give event onclick to rows not hidden
for(var i=0, i<rangs.length; i++) {
if(rangs[i].className=!='hide') {
rangs[i].onclick = function() {
insertDatas(this);
};
}
}
}

function rowIndex(what) {
for(var i=0, i<rangs.length; i++) {
if(rangs[i]==what) return i;
}
}

function insertDatas(what) {
var idx = rowIndex(what);
var targ = rangs[idx];
targ = targ.getElementsByTagName('TD')[0];
var url = 'myDatas/'+(idx/2)+'.txt';
XHR();
http_request.onreadystatechange = function(){ inserContents(targ);};
http_request.open('GET', url, true);
http_request.send(null);
}

function inserContents(where) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
where.innerHTML = http_request.responseText;
}
else {
alert('Problem with request.');
}
}
}

function XHR() {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!http_request) {
alert('Abandon : Impossible de créer une instance XMLHTTP');
return false;
}
return http_request;
}

</script>

<style type="text/css">
..hide { display: none;
</style>

<table id="myTable">
<tbody>
<tr><td>test 1</td></tr>
<tr class="hide'><td></td></tr>
<tr><td>test 2</td></tr>
<tr class="hide'><td></td></tr>
</tbody>
</table>

datas :
- in folder : myDatas
- files : 0.txt, 1.txt, 2.txt ...

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 19 '07 #2
ASM
ASM a écrit :
Cacho a écrit :
>>
I guess it could be simple

Not really ...
some errors in code given ...

code working :
http://stephane.moriaux.perso.wanado...c/insertDatas/

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 19 '07 #3

On 19 ene, 03:12, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
ASM a écrit :
Cacho a écrit :
I guess it could be simple
Not really ...some errors in code given ...

code working :http://stephane.moriaux.perso.wanado...c/insertDatas/

Hi

Thanks for your reply.

I dont want to retrieve a file. I need to just call a servlet and paste
the xhtml code returned by it.

The process could be similar to the one you sent, right ?

Thank you

C

Jan 19 '07 #4
ASM
Cacho a écrit :
On 19 ene, 03:12, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
>ASM a écrit :
code working :http://stephane.moriaux.perso.wanado...c/insertDatas/
I dont want to retrieve a file. I need to just call a servlet and paste
the xhtml code returned by it.

The process could be similar to the one you sent, right ?
servlet means something server side no?
so, I think you'i need XMLHttpRequest.

And, yes I hope it could be similar as simple given example.

Tell back if it works.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 19 '07 #5
Cacho wrote:
>
I dont want to retrieve a file. I need to just call a servlet and paste
the xhtml code returned by it.
The world's worst (and most numerous) browser doesn't supported
inserting XML fetched via XMLHTTPrequest into the current DOM. You will
be better off using text (probably JSON) and building the additional DOM
elements from that.

Unless your users are known to be using a decent modern browser.

--
Ian Collins.
Jan 19 '07 #6

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

Similar topics

5
by: Steve Franks | last post by:
Is there any way to tell VS to automatically reformat my HTML view to add lines and tabs/spacing to create nicely formatted HTML in the viewer? I am using Visual Studio 2005 .NET Beta 2 For...
1
by: rockdale | last post by:
Hi, all I am coding a asp.net application as user data entry and report interface. We also have another C#.net appplication (a server) does some other stuff, my webserver can send and receive...
2
by: sarafat | last post by:
greetings people I am new to Ajax and javascript, yet i have little time to learn it all. Question is: i am using javascript to create my DOM Table and AJAX that returns a DataSet to my...
4
by: finecur | last post by:
I am working on the project. Here is the work flow. server. The server will do some calculation based on the data in the file and return an image in Jpg format. The returned image will be...
1
by: drchaos | last post by:
Placing HTML code with inline javascript into a div both as rendered HTML(the intended final purpose) and shown as RAW text HTML (for the user to copy and paste into their own webpage.) Here is...
6
by: patrice.fiset | last post by:
Hi all, When I send the html email, the only thing I receive is the tags (the html codes basically). I want to be able to see the email like a html page, what is wrong with my code? Here is a...
8
by: Samik R. | last post by:
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...
10
dj12345
by: dj12345 | last post by:
Hi, (Asp.net + Ajax) I am creating a page which will fetch data from server without postbak of a page.. I have 2 controls on this page TextBox and Lable. I have assigned TextBoxWatermark...
5
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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...

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.