Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    120
    Thanks
    1
    Thanked 0 Times in 0 Posts

    simple ajax replace but with many links

    Hello, can anyone help me with this function?

    i'm doing a replace, the content appears inside the div "foo".

    now i want to have like 3 or 4 links with the funcione replace and each one replace his own content.

    my code so far and working is:

    Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    var http = false;
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    } 
    function replace() {
      http.open("GET", "conteudo.php?id=1", true);
      http.onreadystatechange=function() {
        if(http.readyState == 4) {
          document.getElementById('foo').innerHTML = http.responseText;
        }
      }
      http.send(null);
    }
    </script> 
     
    </head>
    <body>
    <div class="accordion_content">
        <h2><p><a href="javascript:replace()">link 1</a></p>
    <div id="foo">
      here appear the content
    </div></h2>
    </body>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    use function parameters
    Code:
    function replace(where, what) {
      http.open("GET", "conteudo.php?id=" + what, true);
      http.onreadystatechange=function() {
        if(http.readyState == 4) {
          document.getElementById(where).innerHTML = http.responseText;
        }
      }
      http.send(null);
    }
    Code:
    <a href="javascript:replace('foo', 1)">link 1</a>
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    120
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you


  •  

    Posting Permissions

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