SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    mUMBAI
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using xml in javascript

    Hi,

    I am calling an xml using javasript.I am able to call the xml but the xml is getting cached on client machine forever.Even though if any changes done in the xml file still the cached xml is used from the client machine.Since the http request is used for calling a xml hence ideally the cached xml is used from the client machine untill its contents are changed.


    Pls find the code I have used...

    pls help before my boss kills me

    // to load the xml
    function loadreq(url)

    {

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
    req_Head = new XMLHttpRequest();
    req = new XMLHttpRequest();
    req.onreadystatechange = processReqChange;
    req.send(null);
    req.open("GET", url,true);
    } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    req_Head = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
    req.onreadystatechange = processReqChange;
    req_Head.open("HEAD", url,true);
    req.open("GET", url, true);
    req.send();

    }
    }
    }


    //to read the xml
    function processReqChange()
    {
    if (req.readyState == 4) {
    if (req.status == 200) {
    var Gujarati_News ;
    var response = req.responseXML.documentElement;
    var news=response.getElementsByTagName("news")
    i= 0
    var news_texts ;
    news_texts = ""

    for(var i=0; i<= news.length-1; i++){
    // create a string
    news_texts = news_texts + "<a href='../quressan/news.asp?newsid=" + news[i].getAttribute("links") +"&typeid="+news[i].getAttribute("typeid")+"'><font size='2' color='#1c355d' face='arial'><b>*" + response.getElementsByTagName("news")[i].firstChild.nodeValue+ ">> </b></font></a>"

    if(news[i].getAttribute("dt_tm")!=""){
    dt_tm = news[i].getAttribute("dt_tm")
    news_texts = news_texts + "<br><font size='1' color='#1c355d' face='arial'>(" + dt_tm + ")</font>"
    }
    news_texts = news_texts + "<br><br>"
    }
    news_text.innerHTML = news_texts ;

    } else {
    alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
    }
    }
    Last edited by shailu; Jul 24, 2006 at 02:25.

  2. #2
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Member jtreefrog's Avatar
    Join Date
    Nov 2003
    Location
    Roseville, Mi
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding a timestamp to the URL in the XHR - I've found that a timestamp will often help with browser caching issues.
    Give a man a match, and he'll be warm for a minute, but set him on fire, and he'll be warm for the rest of his life.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •