Navigate
Home
ArticleWiki
Forum
Newsletter
Links
Tech News
Welcome Guest.
Username:

Password:

Remember me

Scripting Remote Images in JavaScript
Welcome, Guest. Please login or register.
February 08, 2012, 05:50:40 PM
11513 Posts in 1262 Topics by 496 Members
Latest Member: Beerdernill
Experts Round Table Network  |  Web Technologies  |  General Web Dev  |  Scripting Remote Images in JavaScript « previous next »
Pages: [1]
Author Topic: Scripting Remote Images in JavaScript  (Read 908 times)
rdivilbiss
Moderator
*
Offline Offline

Posts: 424



WWW
« on: January 31, 2007, 09:56:58 AM »

Discussions from: http://www.expertsrt.com/articles/Rod/imageAjaxNot.php
Logged

Rod
rdivilbiss
Moderator
*
Offline Offline

Posts: 424



WWW
« Reply #1 on: January 31, 2007, 10:04:04 AM »

Quote from: sathyar

Hi Rod,

I refered the below mentioned article, it helps me lot. But atlast i am not able to solve my issue.

http://www.expertsrt.com/articles/Rod/imageAjaxNot.php

I developed a dashboard which contain multiple placeholder, some of them contain images and other placeholders have tables structure data's.

For server side i am using servlets.

One main servlet will dispatch request to other servlet and atlast the main servlet will return html page.

What i want to do is, for refreshing the placeholder i have to use AJAX.

So in servlet if any request is like ajax=true then i set contenttype = text/xml and i return xml type data

for ex : <path><![CDATA[/CygNet_Html/AlarmGraph.jpg]]></path>

On the body part of the html i am calling the function getProfile

for ex: <body onload=\"getProfile()\">

below is the javascript and sample html which i used.

PROBLEM IS, ITS REFRESHING, I AM GETTING ALERTS AND IMAGES ALSO CREATED WHEN JAVASCRIPT CALLING SERVLET. BUT IN THE PLACEHOLDER THE SHOWING THE SAME, ITS NOT SHOWING THE NEW ONE.

Aim is , it is a graph image, if some values are decrease and increase we will show it in the image. the image will create on the same name

My JavaScript code is

 var httpRequest;
 var SlideShowSpeed = 60000;
   
 function getProfile()
    {
    var url = "/servlets/CygNet.Html.Alarms.DashBoardGraphNetworkElementsDown?dashboard=true&ajax=true";
    alert (url);
        if (window.ActiveXObject)
        {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if (window.XMLHttpRequest)
        {
            httpRequest = new XMLHttpRequest();
        }
       
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange = function() {processRequest(); } ;
        httpRequest.send(null);
   }
 
    function processRequest()
    {
        if (httpRequest.readyState == 4)
        {
            if(httpRequest.status == 200)
            {
                var profileXML = httpRequest.responseXML.getElementsByTagName("path")[0];
        alert(profileXML);
        alert("<img src='"+profileXML.childNodes[0].nodeValue+"'>");
        alert (document.all);
        alert(document.getElementById);
        alert(profileXML.childNodes[0].nodeValue);
        var pImageURL = profileXML.childNodes[0].nodeValue;
       

        /*var img=new Image();
        img.src=pImageURL;
        document.getElementById('imgAjax').src=img.src;*/
        /*var img = document.createElement('img');
            img.onload = function (evt) {
                    document.getElementById('imgAjax').src=this.src;
                document.getElementById('imgAjax').width=this.width;
                document.getElementById('imgAjax').height=this.height;
            }
        img.src = pImageURL;*/


        var img=new Image();
            img.src=pImageURL;
            document.getElementById('imgDiv').innerHTML="<img border=0 src='"+pImageURL+"'>";


                //document.getElementById("imgDiv").innerHTML="<img src='"+profileXML.childNodes[0].nodeValue+"'>";
            //if (document.all||document.getElementById){
                tss=setTimeout('getProfile()', SlideShowSpeed);
        //}

                //updateHTML(profileXML);
            }
            else
            {
                alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
            }
        }
    }
       
 
//////////////HTML SAMPLE.

<div id="wrapper1"><div
 id="dragableElementsParentBox">
<div class="panel"
dragableBox="true" id="panel2"><
div class="headingbg"><div class=
"heading">Alarm Graph - Severity Basis</div></div><div class= "img" id="imgDiv"> <img  id="imgAjax" src="/CygNet_Html/AlarmGraph.jpg">
</div
></div>



kindly help me in this regard.

thanks & regards,

sathya.r

Logged

Rod
rdivilbiss
Moderator
*
Offline Offline

Posts: 424



WWW
« Reply #2 on: January 31, 2007, 10:14:28 AM »

I've barely scanned your code, so this is just a quick observation.

Are you retrieving the image URL with AJAX, and then calling the remote image function with the returned image URL?

« Last Edit: January 31, 2007, 10:21:14 AM by rdivilbiss » Logged

Rod
COBOLdinosaur
Moderator
*
Offline Offline

Posts: 481



WWW
« Reply #3 on: January 31, 2007, 07:19:47 PM »

if the file name of the image is the same, how does the browser know it has to swap it.  IF you set the src to the value it already has, is it not going to continue using whatever is already in active memory?
Logged
VGR
Mentor

Offline Offline

Posts: 724



WWW
« Reply #4 on: March 09, 2007, 10:38:24 AM »

I dunno if you feel the same as me, but It made me think of a technique I documented one year ago to create images on the fly.
This is for server-side generation on-the-fly in the middle of an HTML output.
So it's kind-of the reverse : the server generates static javascript/HTML that holds a dynamic image generated on-the-fly (or : not out of disk) without having to bother about output having started etc

dunno if it's linked to your technique or not (not enough time) but you ma be interested

it's explained at http://www.europeanexperts.org/question/TOUTES/ZONES/1453.html and visible online

regards
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
Pages: [1]
« previous next »
    Jump to: