2

I have some modal in index.php and want to load content into my modal with ajax request to ajax.php. when i try to load the content with ajax.php the response inner ajax.php has load normaly but my .js in index.php not load for example my datepicker is not loaded inside modals

Call Function :

AJAX Request :

<script>
        function addProduct(str) {
            if (str=="") {
                document.getElementById("responseModal").innerHTML="";
                return;
            } 
            if (window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            } else { // code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    document.getElementById("responseModal").innerHTML=xmlhttp.responseText;
                }
        }
        xmlhttp.open("GET","SERVER/ajax.php?id="+str,true);
        xmlhttp.send();
    }
</script>

My Modal:

            <div class="xx-modal" id="open-modal">
                <div class="xx-modal-dialog">
                    <button class="xx-modal-close uk-close" type="button"></button>
                    <div id="responseModal">Waiting For AJAX to Load!</div>
                </div>
            </div>

And This My JavaScript Src that i want to included inside my modal

    <script src="example.com/static/assets/js/xxxx.js"></script>
    <script src="example.com/static/assets/js/xxxx.js"></script>
    <script src="example.com/static/assets/js/xxxx.js"></script>
    
    
Bayu Dwiyan Satria
  • 986
  • 12
  • 28
  • Possible duplicate of [Dynamically added javascript with external script doesn't get executed](https://stackoverflow.com/questions/38476544/dynamically-added-javascript-with-external-script-doesnt-get-executed) – Kaddath May 04 '18 at 09:26
  • i've tried but not work, but i've solved my case thanks anyway – Bayu Dwiyan Satria May 05 '18 at 07:18

1 Answers1

0
 if (this.readyState == 4 && this.status == 200) {
            document.getElementById("responseModal").innerHTML =
            this.responseText;
       }

You problems is THIS this.responseText

Carlos R
  • 11
  • 6