The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> getting data to display as html nodes and not as text
larry wales
post Oct 1 2007, 07:17 PM
Post #1





Group: Members
Posts: 1
Joined: 1-October 07
Member No.: 3,958



Hi,

I'm working on an ecommerce application for school and am trying to get a simple AJAX function to query database and return some images to a web page. So far, I've managed to successfully do all except for the final step: I can't manage to get the returned data to appear as thumb images in the document.

I am 100% certain that the returned data is:

<a href="?id=1"><img src="images/thumbs/1.1.png" class="thumbox" /></a>;
<a href="?id=4"><img src="images/thumbs/2.1.png" class="thumbox" /></a>;


The callback function I'm using is:

CODE
function callback() {
    if (request.readyState==4) {
        if (request.status == 200) {
            var id = document.getElementById('categoryThumbBox');

            id.appendChild(request.responseText);
        }
    }
}


This produces the following error:

[Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost:8084/kramekznamek/js/javascript.js :: callback :: line 22" data: no]

I'm fairly sure the problem lies in using the right method with 'id'.

Also, interestingly enough, if I type in "document.write(request.responseText)" as a test, I see exactly what I'm wanting: two thumb images.

If anyone has any suggestions, I'd be really grateful smile.gif

thanks,
larry

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Oct 2 2007, 03:03 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



Maybe you'll find an answer from one of the links at http://www.d.umn.edu/itss/support/Training...cript.html#ajax.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 2 2007, 09:21 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,663
Joined: 10-August 06
Member No.: 7



QUOTE(larry wales @ Oct 2 2007, 02:17 AM) *

if I type in "document.write(request.responseText)" as a test, I see exactly what I'm wanting: two thumb images.

Could it be that it's a string? You can test that with the nodeName property: http://www.quirksmode.org/dom/w3c_core.html
AFAIK you can't use appendChild with strings, instead you must create an element and give it attributes and values using DOM methods. See http://developer.mozilla.org/en/docs/Trave..._DOM_Interfaces
If you must use a string you might use the innerHTML property instead of the DOM.

Of course none of this will work for users with JS disabled...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 4th May 2024 - 04:30 PM