1

i have a small problem... i have a content-management.php, in this page, i set $a variable, and i calling it in script from javascript drop down select. but it is not include file layout-inc/icerik.php. how can i fix it ? where is my mistake?

<?php
$a = '<?php include "layout-inc/icerik.php";?>';
?>

<script>

            var gm=$("#mycanvas").gridmanager({

                debug:1,
                customControls: {
                    global_col: [{ callback: 'btn', loc: 'top', iconClass: 'fa fa-th-large' }]
                }
            }).data('gridmanager');
            $(".submit").on("click", function(e){
                canvas = gm.$el.find("#" + gm.options.canvasId);
                gm.deinitCanvas();
                $("#mycontent").val(canvas.html());
                $(this).submit();
                $('.dropdown-toggle').dropdown();
            });


        function btn(container, btnElem) {

          bootbox.dialog({
              message: '<div class="container-fluid">' +
              '<div class="col-md-12">' +
              '<form class="form-horizontal"> ' +
              '<div class="form-group"> ' +
              '<label for="sel1">Select list (select one):</label>'+
              '<select class="form-control" name="sel1" value="" id="sel1">'+
              '<option value="<?php echo $a ;?>"> Content Module</option>'+
              '<option value="tesmodule"> TEST Module</option>'+
              '</select>'+
              '</form> </div> </div></div>',
            title: "Please select a value",
            buttons:{
              success: {
                label: "Gönder",
                className: "btn-success",

                  callback: function(){
                  var html="",
                     $a =  document.getElementById("sel1").value,
                    html= $a;
                    gm.addEditableAreaClick(container, btnElem, html);
                  }
              }
            }
          });

        }
        </script>
  • 2
    php is serverside pre-processor that sends a complete page to client ... javascript runs in the client - it has no direct access to the source (php) of the page that created it – Jaromanda X Sep 07 '16 at 06:34
  • my page is .php –  Sep 07 '16 at 06:35
  • 1
    yes it is, do you understand that the page in the browser is HTML, which your PHP page has produced, the all the processing occurred on the server, then it sent a single page which your browser has rendered for you - and there is no two way communication between the source PHP and the final html in the browser? – Jaromanda X Sep 07 '16 at 06:36
  • but, all javascript codes and php codes in same .php page. and also i try to include in .php page. –  Sep 07 '16 at 06:38
  • other ways? how can i do it ? –  Sep 07 '16 at 06:44
  • first you have to understand how PHP works - you haven't included anything in that code snippet, you've created a variable in PHP that has text which include the word include, but it hasn't actually included anything, it's just a string of text – Jaromanda X Sep 07 '16 at 06:45

1 Answers1

0

You cannot include a PHP file within JavaScript in a Browser enviroment. JS is client technology when instead PHP is a server technology.

Generally speaking you can apply the following solutions if you need two part of your application to intereact:

  • Make your server and client talk using AJAX, sockets or similar technologies.
  • For very simple problems, you can create JavaScript file dynamically at server side (using PHP) and delivery them to the client which will process the JS code generated, but you cannot do the opposit.
GibboK
  • 71,848
  • 143
  • 435
  • 658