Urgent: how to change image url retrieve by ajax to display as a image?

hi
i am using ajax to retrieve the img url path how am i going to use the img url path i retrieve and display as a image and i using javascript language
anyone know?
if can show me example of how to do that
i try the follow way but don’t work what wrong?

    
 var descIg = "";
descIg += rssent[i].descImg;
 var placeImg = document.createElement('img');
    placeImg.src = descIg;

placeImg is an image, but it’s floating free at the moment. You haven’t attached it to the DOM yet.

then how to create a img with the img url retrieve by the ajax???

You have already created the image. All that you need to do now is to attach that image to the DOM.

u mean the img url is what u mean as has created the img? to the dom?can show me an example

The createElement part is what creates the image element. The src part is where you associate an image with the image element.

One example is where you gain a reference to the parent of where the image will be. A simple example of that is:


var parent = document.getElementById('container');
parent.appendChild(placeImg);

How you will do it though, depends entirely on where in the DOM you want the image to be placed.

i want to put the img in the dojo content pane
which is like

var c1 = new dijit.layout.ContentPane({
content: “placeImg”
})

if this way how am i going to use it?

With “placeImg” it will only be that text string that is added as content. You should use placeImg without the quotes to use the image that you created.

You may have to ask at other placed for dojo-specific info though. There are some dojo forums that can be of more help with dojo-related issues.

okay can i ask you regarding ajax
how am i going to call the title
because normally if you call start year is like
var detail = eval…
then for loop it
inside should be
var start year=“”
startyear += …[i].startyear
something like this but how am i going to call the title inside the images?


{
"infos": {
"info": [
{
"startYear": "1900",
"endYear": "1930",
"timeZoneDesc": "daweerrewereopreproewropewredfkfdufssfsfsfsfrerewrBlahhhhh..",
"timeZoneID": "1",
"image": {
"images": [
{
"id": "1",
"thumb": "images/bird.jpg",
"large": "images/bird.jpg",
"title": "Bird",
"imgDesc": "i can fly"
},
{
"id": "2",
"thumb": "images/dog.jpg",
"large": "images/dog.jpg"
"title": "Dog",
"imgDesc": "i can bark"
},
{
"id": "3",
"thumb": "images/bird.jpg",
"large": "images/bird.jpg",
"title": "Bird",
"imgDesc": "i can fly"
}
}
]
}
}

Indenting the code is important to help you see how to access different parts of it.


{
    "infos": {
        "info": [
            {
                "startYear": "1900",
                "endYear": "1930",
                "timeZoneDesc": "daweerrewereopreproewropewredfkfdufssfsfsfsfrerewrBlahhhhh..",
                "timeZoneID": "1",
                "image": {
                    "images": [
                        {
                            "id": "1",
                            "thumb": "images/bird.jpg",
                            "large": "images/bird.jpg",
                            "title": "Bird",
                            "imgDesc": "i can fly"
                        }, {
                            "id": "2",
                            "thumb": "images/dog.jpg",
                            "large": "images/dog.jpg",
                            "title": "Dog",
                            "imgDesc": "i can bark"
                        }, {
                            "id": "3",
                            "thumb": "images/bird.jpg",
                            "large": "images/bird.jpg",
                            "title": "Bird",
                            "imgDesc": "i can fly"
                        }
                    ]
                }
            }
        ]
    }
}

I fixed the missing comma in the second image, after the large image name too.

the how to call the title?
cause when i call the title i try this
var detail = eval…
then for loop it
inside should be
var title=“”
startyear += …[i].image.images.title
but it give me error of is null or not an object

Do you in the indented code, how that images object contains an array?

what do you mean by indented code?
what array?


mygetrequests.onreadystatechange = function() {

            if (mygetrequests.readyState == 4) {
                if (mygetrequests.status == 200 || window.location.href.indexOf("href") == -1) {
                    var detail = dojo.fromJson("(" + mygetrequests.responseText + ")");
                    var rssent = detail.infos.info;
for (var i = 0; i < rssent.length; i++) {
var title = "";
title += rssent[i].image.images.title
document.getElementById("txtHint").innerHTML = title // the txtHint is div created

See post #11

See the square brackets, highlighted in blue


"images": [color="blue"][[/color]
    {
        ...
        ...
    }
[color="blue"]][/color]

okay , then ? i want to go from the to the title? so how shld i write i know you say indented code is impt…this is hw it look lk the json? cause i gt the var detail = eval(…reponseText)…then i want to get to the title, so i write this detail.infos.info.image.images.title …is this the indenting ?but i got a error which is null or not a object
what you mean by how that obj contain a array
can just tell me why i got this error ? and how should i solve it?

You are getting the error because images contains an array, but you are trying to instead access a property of images called title.
Because it is an array, no property called title exists.

What you need to do instead is to access one of the three array indexes, each of which contains (among other properties) the title property.

what you mean by array indexes?
can show me how it done?

This is an array.


var items = ['apple', 'banana', 'citrus'];

The items in the array are accessed using an array index, starting from 0 for the first item. For example:


var item = items[1];
// item is 'banana'

The [1] part is the array index.

but is this still like json format if i change to this way?
if i change how should it look like and how am i going to get it the title

p.s sorry that i keep asking , cause this is my first time learning this

Which title do you want? There are three images in your JSON data.

Is it only the first one that you ever way to use, or will you be doing things with all three of the image titles?