- Joined
- Mar 11, 2011
- Messages
- 583
I figured out the solution to this problem about an hour after posting this. My solution can be found at the bottom of this post.
I'm trying to create a file browser and editor using PHP and jQuery. I've got the browser down, and I had the editor working.
However, the way I was doing the editor, the entire page had to refresh, causing all of the directories that were open to close. So, I had to scrap that way and try something else - submitting an invisible form using jQuery.
I followed the tutorial here, and I think that's all working good and fine. However, now I need to fetch information from the page I submitted the form to so that I can display it in the editor.
Here's what I have:
I'm hoping/guessing that there's a way that the target file (in this case "filemgr/open.php") can return data back to the page that sent the form. I'm not sure if there's some special variable that I can replace "File data goes here" with, or if I somehow need open.php to submit a form back to the editor page by itself.
Any input is appreciated. Thanks!
SOLUTION
I added the word "data" in a couple places to make the actual fix:
To my knowledge, adding "data" as a parameter in the success function allows you to store the HTML or XML output of the target page for later use.
That being said, here's what's in open.php:
if ( count( $_POST ) > 0 )
{
if ( isset( $_POST['filename'] ) )
{
$fileContent = "";
$data = file( "../" . $_POST['filename'] );
foreach( $data as $value )
{
$fileContent .= $value;
}
echo $fileContent;
}
}
(couldn't seem to put the code inside quote/code tags
)
I'm trying to create a file browser and editor using PHP and jQuery. I've got the browser down, and I had the editor working.
However, the way I was doing the editor, the entire page had to refresh, causing all of the directories that were open to close. So, I had to scrap that way and try something else - submitting an invisible form using jQuery.
I followed the tutorial here, and I think that's all working good and fine. However, now I need to fetch information from the page I submitted the form to so that I can display it in the editor.
Here's what I have:
Code:
function openFile(file)
{
var dataString = "filename=" + file;
$.ajax({
type: "POST",
url: "filemgr/open.php",
data: dataString,
success: function()
{
$("#main-textarea").val("File data goes here");
}
});
}
I'm hoping/guessing that there's a way that the target file (in this case "filemgr/open.php") can return data back to the page that sent the form. I'm not sure if there's some special variable that I can replace "File data goes here" with, or if I somehow need open.php to submit a form back to the editor page by itself.
Any input is appreciated. Thanks!
SOLUTION
I added the word "data" in a couple places to make the actual fix:
Code:
function openFile(file)
{
var dataString = "filename=" + file;
$.ajax({
type: "POST",
url: "filemgr/open.php",
data: dataString,
success: function([b]data[/b])
{
$("#main-textarea").val([b]data[/b]);
}
});
}
To my knowledge, adding "data" as a parameter in the success function allows you to store the HTML or XML output of the target page for later use.
That being said, here's what's in open.php:
if ( count( $_POST ) > 0 )
{
if ( isset( $_POST['filename'] ) )
{
$fileContent = "";
$data = file( "../" . $_POST['filename'] );
foreach( $data as $value )
{
$fileContent .= $value;
}
echo $fileContent;
}
}
(couldn't seem to put the code inside quote/code tags
)
Last edited:



