-1

I have working code but my code doesn't include with ajax js code from php file. Problem is that javascript from second script is not working. Ajax call can't enable to execute js script from second file Here is ajax code. My question is this good call for php file with working js functions because those working js functions does't work if I call them with this ajax code?

<script>$.ajax({
                                url: "getSubcategorieFormUpdate.php?id=" + activeSubcategorie + "&sifra_novogradnja=<?php echo $sifra_novogradnja ?>",
                                method: "GET",
                                dataType: 'text',
                                success: function (result) {                                     document.getElementById("advertForm").innerHTML = result;
                                }
                            });</script>
  • 1
    Possible duplicate of [JavaScript in php file doesn't work when php file is called using Ajax](https://stackoverflow.com/questions/21386761/javascript-in-php-file-doesnt-work-when-php-file-is-called-using-ajax) – Amit Joshi Aug 16 '17 at 20:37
  • Can I make similar js call without ajax? – Mario Petrović Aug 16 '17 at 20:45

1 Answers1

0

I'm not sure if I understood your question properly, but if I did, then no. You shouldn't insert javascript code to php file which you are calling through javascript.

If you want to call ajax twice just do it in javascript file.

$.ajax({
    url: "yourUrl.php",
    method: "GET",
    data: {id: 'id'},
    success: function(data) {
        $.ajax({
            url: "getSubcategorieFormUpdate.php?id=" + activeSubcategorie + "&sifra_novogradnja=" + data.sifra_novogradnja,
            method: "GET",
            dataType: 'text',
            success: function(result) {                                     
                document.getElementById("advertForm").innerHTML = result;
            }
        });
    }
});

If it's not what you wanted then please specify what did I misunderstand :)

Regards, KJ

Krzysztof Janiszewski
  • 3,763
  • 3
  • 18
  • 38