Help - Search - Members - Calendar
Full Version: getting data to display as html nodes and not as text
HTMLHelp Forums > Programming > Client-side Scripting
larry wales
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

Frederiek
Maybe you'll find an answer from one of the links at http://www.d.umn.edu/itss/support/Training...cript.html#ajax.
Christian J
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...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.