dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Call JS function after AJAX

  1. #1
    Join Date
    Apr 2009
    Posts
    1

    Red face Call JS function after AJAX

    Hi,
    I've come across the common problem within AJAX and I can't call a function already on the page that AJAX has dumped another page into. I've tried everything and asked all around the internet with little helpful supply. Other peoples scripts don't work for mine and I couldn't get anything working with eval().

    Here's 2 pages:
    index.php:
    HTML Code:
    <html>
    <head>
    <title>AJAX</title>
    <script type="text/javascript">
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    	try {
    		xmlhttp = new XMLHttpRequest();
    	} catch (e) {
    		xmlhttp=false;
    	}
    }
    if (!xmlhttp && window.createRequest) {
    	try {
    		xmlhttp = window.createRequest();
    	} catch (e) {
    		xmlhttp=false;
    	}
    }
    function loadajax(){
    xmlhttp.open("GET", "ajax.php",true);
     xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
      document.getElementById("show").innerHTML = xmlhttp.responseText;
      }
     }
     xmlhttp.send(null)
    }
    </script>
    </head>
    
    <body>
    <a href="javascript:loadajax();">Load AJAX Page</a><br />
    <div id="show">AJAX will go here</div>
    </body>
    </html>
    ajax.php
    HTML Code:
    <script type="text/javascript">
    function test(){
    	alert("This doesn't work!");
    }
    </script>
    <a href="javascript:test();">Click Me</a>
    The link doesn't show the alert like it's meant to.
    Any help really would be appreciated,
    Sephers.

  2. #2
    Join Date
    May 2009
    Posts
    2
    I've gotten round this limitation by writing a response to a hidden IFrame.
    The response contains any JavaScript function calls needed, but must be preceeded by a parent reference.

Similar Threads

  1. using an AJAX function to return a value
    By k285715 in forum AJAX
    Replies: 0
    Last Post: 06-18-2007, 11:06 AM
  2. Thanks!!! Re: call c/c++ function from VB
    By Chris in forum VB Classic
    Replies: 1
    Last Post: 08-08-2002, 11:02 AM
  3. AnimateWindow API
    By Tim Manos in forum VB Classic
    Replies: 4
    Last Post: 10-19-2001, 06:06 AM
  4. Replies: 2
    Last Post: 06-05-2001, 01:55 PM
  5. Re: Dll function call problem - Same problem
    By Fabian in forum VB Classic
    Replies: 7
    Last Post: 06-28-2000, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center