473,406 Members | 2,620 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,406 software developers and data experts.

InnerHTML vs Ajax

3
Recently, I have been attempting to pick up AJAX and discovered a slight problem with innerHTML..

I have

Expand|Select|Wrap|Line Numbers
  1. <div id='container'></div>
  2.  
then ..

Expand|Select|Wrap|Line Numbers
  1. $('container').innerHTML=req.responseText;
  2.  
The content shows up but when I view source, the <div id='container'> </div> tag shows up as EMPTY, does not input the new content, although the browser displays the ajax reponse in the div, to the user... I assume that innerHTML displays the content directly to the screen but does not update the content between the <div> </div> .. which brings up another problem as my javascript for ajax-in-place-editor references some <div> which was supposed to show up between the <div id='container'> </div> tag ...

What should have been displayed:
eg.

Expand|Select|Wrap|Line Numbers
  1. <div id='container'> 
  2. <div id='header_1'>hello1</div>
  3. <div id='header_2'>hello2</div>
  4. <div id='header_3'>hello3</div>
  5. </div>
  6.  
instead, it is showing

Expand|Select|Wrap|Line Numbers
  1. <div id='container'></div> 
  2.  
as before, and is EMPTY in between those tags (although the browser shows
hello1,hello2,hello3) but my javascript breaks here, since it cannot find <div id='header_1'> ... and 2, and 3, and so forth..

Any idea how I could solve this problem?
Any help is appreciated! Thanks!
Jul 29 '09 #1
6 5378
Dormilich
8,658 Expert Mod 8TB
doesn't jquery provide a method for that?
Jul 29 '09 #2
rayliu
3
Hi there, thanks for your prompt reply!
hmm actually at the moment I'm using prototype instead of jquery.. would that be a problem in resolving this issue?
Jul 29 '09 #3
Dormilich
8,658 Expert Mod 8TB
I guess not.
..............
Jul 29 '09 #4
Canabeez
126 100+
"View Source" does not show any JavaScript generated source (except document.write() method in some cases). Firefox Developer Plugin has an option of "View Generated Source", which might help you, otherwise you could always alert(document.getElementById('container').innerHT ML); or set it as value to some textarea.
Jul 29 '09 #5
rayliu
3
Thanks for your help!
I did read something about putting this into the address bar

javascript:'<xmp>' + window.document.body.outerHTML+ '</xmp>'

that will show the javascript generated source as well..

I have solved the bug, so far I realised that javascript that references to the <div> does work, even though it can't see it.. but only after I've used prototype's element update method.. I believe it does something similar to eval() which makes the javascript works ...

However if you only use the conventional

$('show').innerHTML = req.responseText;

it will not work as the generated javascript does not run.. so I believe as Dormilich has kindly advised earlier, jQuery and Prototype both have their own update method instead of using the direct $('container').innerHTML = req.responseText method.

Once again, thanks!
Aug 1 '09 #6
You can have firebug addon for Firefox. Using that you can see the dynamic html changes in an element.
Aug 1 '09 #7

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

Similar topics

8
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this...
4
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the...
5
by: noddy | last post by:
The full code relating to this question can be found at http://marc.info/?l=php-general&m=112198633625636&w=2 It describes a bare bones way of making an AJAX request. It works fine for me except...
4
by: coby | last post by:
I have an application with a form that has two parts : A & B. A should be a static form while B shoudl be dynamically loaded via AJAX/PHP. Using a select box on part A, the onchange event calls...
8
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this...
1
by: Tarik Monem | last post by:
I have been able to successfully retrieve data from an xml file, where the data has been massaged a little bit, to create a table to be retrieved and it is displayed via a document.writeln within a...
3
by: divyaphilip | last post by:
Hi, I have a javascript function that uses ajax to set a div based on a query. The javascript function is invoked on a button click and uses ajax like this: function validDate(node,roomid) {...
1
by: Robin | last post by:
Martin wrote: .... You appear to be putting the responseText into DIV 'htmlText' then 'hiddenDiv'. You therefore have two DIVs with id 'divslct4' (not legal as IDs are supposed to be...
4
by: phub11 | last post by:
Hi all, I have started using AJAX to populate drop downs from a mySQL database; however, I want the option of modifying the selected OPTION of the drop down using an array of radiobuttons...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
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...
0
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...

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.