troubleshooting Question

Code not seeing another code from other folders in project

Avatar of Ivan Golubar
Ivan Golubar asked on
JavaScriptPHPWordPress
14 Comments1 Solution263 ViewsLast Modified:
I am working on a project and i am including code from different resources from the net. Now i have beginning to get problems. With "code not seeing another code ". I will explain on particular example:
My project tree is as next
project_folder
     header.php
     functions.php
     PgetJson.php
     js_folder 
       JSgetJson.js
       fabric.min.js
     sub_folder
       another.php
In functions.php I am using wp_enqueue_script and wp_enqueue_style  to include js and css  files to project (custom Word press theme)
In header.php i have a canvas  <canvas class="objectcanvas" id="c" width="980" height="500" > 
and in JSgetJson.js I am getting Json to display on canvas:
function getJsonF(){ ////////////////////////////////////                              JSgetjson
var whichProjectToSave=document.getElementById("selectProjectID").value;
$.ajax({
  method:"POST",
  url: '/wp-content/themes/net/PgJson.php',
  data:  {
    "getCanvas":1,
    "whichProject":whichProjectToSave,
    },
    datatype: "text",
    success: function(strdate){
   canvas.loadFromJSON(strdate, function() {
    // console .log(strdate);
     canvas.renderAll();     
      });
     }
 }); 
}
from the server with  code from PgetJson.php
<?php //////////////////////////////////////////////////               PgetJson.php  
$db2=mysqli_connect("localhost","ccc","ccc2","222cl_projectObjects")or die ("no connection"); 
                    
       if (isset($_POST["getCanvas"]) ) {  
               $projectName= mysqli_real_escape_string($db2, $_POST['whichProject']);
              $query = "SELECT objectsList FROM projectObjectstable  WHERE projectName='$projectName'";
              $jsonCanvas= mysqli_query($db2,$query);
                    $row = mysqli_fetch_row($jsonCanvas);
                    $myLine=$row['0'];
                    echo $myLine;
       }
        mysqli_close($db2);
?>

Until here everything works fine.

But am getting in troubles when i want to display the same Json in another.php on next canvas:
 <canvas class="objectcanvas" id="c7" width="200" height="200" backgroundColor= "red" > 
I have a problem alreday when i want to display canvas.
This is the error:
Uncaught ReferenceError: fabric is not defined at .....
Uncaught TypeError: Cannot create property 'style' on string 'c7' at i._createCanvasElement (fabric.min.js:2)

I am opening another.php page from the link in header.php.

And another.php is as next:
<?php
...........
>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
....
.........
</style>
<script type="text/javascript">
.......
 var canvas = new fabric.Canvas('c7');
...........
</script>
</head>
<body>
.......
........
 <canvas class="objectcanvas" id="c7" width="100" height="100" backgroundColor= "red" > 
........
............
</body>
</html>

I hope that i gave enough information to start from somewhere.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros