... z.B. um jQuery-Events an neu geladene Elemente zu binden.

 

Quelle siehe: http://stackoverflow.com/questions/510779/calling-a-javascript-function-returned-from-an-ajax-response

 

PHP side code Name of file class.sendCode.php

 

<?php
class sendCode {

function __construct($dateini,$datefin){ echo $this->printCode($dateini,$datefin); } function printCode($dateini,$datefin){ $code =" alert ('code Coming from AJAX {$this->dateini} and {$this->datefin}');";//Insert all the code you want to execute, //only javascript or jQuery code, don't incluce <script> tags return $code ; }
}
new sendCode($_POST['dateini'],$_POST['datefin']);
...
?>

Now from your Html page you must trigger the ajax function to send the data.

...  <script src="/http://code.jquery.com/jquery-1.9.1.js"></script>....Datebegin:<input type="text" id="startdate"><br>Dateend:<input type="text" id="enddate"><br><input type="button" value="validate'" onclick="triggerAjax()"/>

Now at our local script.js we will define the ajax

function triggerAjax(){
    $.ajax({
            type:"POST",
            url:'class.sendCode.php',
            dataType:"HTML",
            data :{

                dateini : $('#startdate').val(),
                datefin : $('#enddate').val()},

                  success:function(data){
                      $.globalEval(data);// here is where the magic is made by executing the data that comes from// the php class.  That is our javascript code to be executed
                  }

        });}
add javascript code to be executed
} });
}