K
K
Kirill Gorelov2015-09-29 11:54:16
PHP
Kirill Gorelov, 2015-09-29 11:54:16

Pass from JS to PHP?

Hello. I have a problem.
I will try to describe in detail.
Task. It is necessary to make the simplest code editor in php. I plan to do editing in .
How I want to do it:
This code gets the address of a file.

<script type="text/javascript">
      $(document).ready( function() {
        $('#fileTreeDemo_1').fileTree({ root: '../../1/', script: 'connectors/jqueryFileTree.php' }, function(file) { 
        var	m = (file);
        // alert(m);
        });
    </script>

I want to transfer this address to a variable in this way.
<?php $a = file_get_contents("путь который надо получить"); ?>
<textarea type="text" name="a1" rows="3" cols="80" > <?php echo $a;?></textarea> 
</script>

This is how it will be easier in my opinion.

Now the problem is how to pass the address of the file. How I do it:
1 way it doesn't work (this is also an example from the internet for a test):
<script type="text/javascript">
$(document).ready(function(){
   $("#test").click(function(event){
     var postVar = "hi";
$.ajax({
url: 'index4.php',
data : 'postVar',
type : "POST",
success: function (data) {
alert (data);
},
error: function(){
alert ("No PHP script: ");
} 
   });
return false;
});
 });
</script>

Now I'm displaying this address
<?php
echo $_POST['postVar'];
?>


Method 2 doesn't work either:
<?php
echo $_GET['m']; //это дополнительно пробую
print $_GET['m']; //это дополнительно пробую
if (isset($_POST['u_name']))
{  
    echo $_POST['u_name'] . '</p>';
}
else
{   
    echo "<script type='text/javascript'>";
    echo "document.write('<textarea>' + m + '</textarea>');";    
    echo "</script>";   
    exit();   
}
?>

This is a script that gets all files and folders in a tree view www.abeautifulsite.net/jquery-file-tree
Displays files like this www.abeautifulsite.net/jquery-file-tree

How to do it right. How to pass the address of a file for editing??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
matperez, 2015-09-29
@matperez

Haven't tried that?

<form action="save">
  <label>some code</label>
  <textarea id="content"></textarea>
</form>

$.get('/source', {'name': 'SomeClass.php'}, function(data) {
  ('#content').val(data);
});

if (isset($_GET['name']) {
    return file_get_contents($_GET['name']);
  }

In general, if you do not need the editor itself, but the ability to edit, why not use something ready- made ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question