Ajax ,XML and browsers

Discussion in 'JavaScript' started by XandroZ, Dec 13, 2006.

  1. #1
    I have 2 problems:

    1.IE, XML and Space

    I need to parse something with java script.The problem is how internet explorer understand space?Un example:
    
    <Li>
      <index>Li_j</index> 
      <name>Lithium</name> 
      <atomic_number>3</atomic_number> 
      <relative_atomic_mass>6.941000</relative_atomic_mass> 
      <melting_point>180.539993</melting_point> 
      <boiling_point>1342.000000</boiling_point> 
      <density>0.530000</density> 
      <covalent_radius>1.230000</covalent_radius> 
      <atomic_radius>2.050000</atomic_radius> 
      <atomic_volume>13.100000</atomic_volume> 
      </Li>
    <Na>
      <index>Li_j</index> 
      <name>Lithium</name> 
      <atomic_number>3</atomic_number> 
      <relative_atomic_mass> </relative_atomic_mass> 
      <melting_point> </melting_point> 
      <boiling_point>1342.000000</boiling_point> 
      <density>0.530000</density> 
      <covalent_radius>1.230000</covalent_radius> 
      <atomic_radius>2.050000</atomic_radius> 
      <atomic_volume>13.100000</atomic_volume> 
      </Na>
    
    
    Code (markup):
    Look at the bold code.When I parse I need to parse a space.
    I select a radio button and put in a div : 180.539993 the value for melting point from Li.When I select another radio button I need to put in the same div a space, but is not doing to do that, it keep the previous and give me a java script error.
    Yes I can put another value and tested and when I parse this value to put space instead in div, but I have to do many modifications to code and that is not realy a option.My question is what to put in the XML
    <melting_point>SPACE</melting_point> that IE consider it a space?

    2.Ajax and Browser Cache

    When I request a particular web page, the browser first tries to load the page from its cache, rather than submitting a new HTTP request.

    If I use a php url I wil use something like this
    
    myRandom=parseInt(Math.random()*99999999);
    myRequest.open("GET", url  + myRandom, true);
    
    Code (markup):
    or I use the current timestamp
    
    myRand= + new Date().getTime();
    
    Code (markup):
    But the problem is I parse with java scripts text and xml files(url) not php and the trick above is not working with this kind of file.
    I can add HTTP headers to the data returned by server-side routines, intended to tell the browser not to cache a particular page,but different browsers have different cache support different header declarations, making it difficult to ensure that pages are not cached.
    What I can do in this situation ?
     
    XandroZ, Dec 13, 2006 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    1.- Try using entities
    ampersand#32;   or   &nbsp;
    Code (markup):
    instead of space. NOTE: Replace "ampersand" with a real ampersand (can't display ok here on DP).

    2.- Using HTTP headers (Expires option) as you said "it difficult to ensure that pages are not cached", not only for browsers cache, even because of proxies cache. My suggestion is using "url mod rewrite" (you can see help on Apache Web Server). Browser request a php with random parameter, and your server replies with a .xml file
     
    ajsa52, Dec 13, 2006 IP
  3. XandroZ

    XandroZ Peon

    Messages:
    395
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It is not working ; the &nbsp not at all and the solution with ampersand gives errors "Object required" and block the page when I select other button.
    You use that and works?
    Here it is the java script code that I use to get values from HTML:
    
    document.getElementById(index_nodes[counter].firstChild.nodeValue).value=density_nodes[counter].firstChild.nodeValue
    
    Code (markup):
    I FF works because they use space like and element but in IE is the problem.
     
    XandroZ, Dec 13, 2006 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    With your XML data would be ok this procedure ?
    If no text or only white spaces -> I put only a space
    else -> I put value

    
    function CleanEmptySymbols( string )
    {
      // string = string.replace('\r', '')
      // string = string.replace('\n', '')
      string = string.replace(' ', '')
      return (string.length == 0) ? false : true 
    }
    
    var aux = density_nodes[counter].firstChild.nodeValue;
    if ( CleanEmptySymbols(aux) )
    {
      document.getElementById(index_nodes[counter].firstChild.nodeValue).value = density_nodes[counter].firstChild.nodeValue;
    }
    else
    {
      document.getElementById(index_nodes[counter].firstChild.nodeValue).value = ' ';
    }
    
    Code (markup):
     
    ajsa52, Dec 13, 2006 IP