473,795 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1531
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=fa lse;

onload = function() {

// rangs = collection of rows -- cible = main target
var rangs = document.getEle mentById('myTab le');
var cible = rangs.getElemen tsByTagName('TB ODY')[0];
rangs = cible.getElemen tsByTagName('TR ');

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

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

function insertDatas(wha t) {
var idx = rowIndex(what);
var targ = rangs[idx];
targ = targ.getElement sByTagName('TD' )[0];
var url = 'myDatas/'+(idx/2)+'.txt';
XHR();
http_request.on readystatechang e = function(){ inserContents(t arg);};
http_request.op en('GET', url, true);
http_request.se nd(null);
}

function inserContents(w here) {
if (http_request.r eadyState == 4) {
if (http_request.s tatus == 200) {
where.innerHTML = http_request.re sponseText;
}
else {
alert('Problem with request.');
}
}
}

function XHR() {
http_request = false;
if (window.XMLHttp Request) { // Mozilla, Safari,...
http_request = new XMLHttpRequest( );
if (http_request.o verrideMimeType ) {
http_request.ov errideMimeType( 'text/xml');
}
}
else if (window.ActiveX Object) { // IE
try {
http_request = new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (e) {
try {
http_request = new ActiveXObject(" Microsoft.XMLHT TP");
}
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'><t d></td></tr>
<tr><td>test 2</td></tr>
<tr class="hide'><t d></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 <stephanemoriau x.NoAd...@wanad oo.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 <stephanemoriau x.NoAd...@wanad oo.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
4239
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 example, let's say I paste this HTML into VS.NET "source" view: <table><tr><td>val1</td><td>val2</td></tr></table> I'd like to issue a command to VS to have it reformat this source and change it to this in the editor:
1
2077
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 message with the C#.net server application. Now the C#.net server application group want me to refresh my webpage to show the real time status when I receive a message from them. I do not think I can do that (correct me if I am wrong). On webserver...
2
1818
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 Javascript to fill information in the table. Code looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
4
1834
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 displayed at the same web page. I do not want to refresh the page so that the user get better experience. How can I do it? Thanks,
1
3040
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 the setup. Yes, this is a heavily dynamic and AJAX driven page. one section shows both a display of raw HTML code for the purpose of a user being able to copy paste this code (which contains inline javascript) into their own webpage. a sample...
6
3255
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 copy paste of it. $HTML = "</html><body><img src='http://www.somewebsite.com/ someimage.jpg'></body></html>"; $headers = "From: $from\r\n";
8
3119
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 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...
10
7433
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 extender to TextBox. Inside a Update panel i have Lable.. and the update panel refreshes each 3 seconds and it fetches data and displays it. But my problem is whenever the data is fetched from Server the textbox watermark flickers. i dont know why it...
5
4468
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
9522
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
10216
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
10165
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
10002
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...
1
7543
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
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3728
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.