1

I do believe am over-complicating this, but I have a jQuery modal that talks with a PHP file. The file has all the form and validation, but it's included in the modal. The event is triggered on right-click (so a user right clicks the folder to edit, selects "Edit", the action below triggers. It's supposed to send the folder id to the modal, so the modal displays the edit form with the correct folder. Right now, it doesn't send anything.)

So I have the jquery (script.js):

"action": function(obj) {
 var data = {'pid': obj.attr("id")};
 $.post("/folder/edit.php", data, function (response) {
   $('#modalEditFolder').modal('show');
 });
 }

// also tried this:
$.post("/folder/edit.php", data, function (response) {   
   $('#modalEditFolder').data('pid', obj.attr("id")).modal('show');
});

// and this

$.ajax({
       type: "POST",
       url: "/view/folder/edit.php",
       data: {pid: obj.attr("id")},
       success: function(html) { 
          $('body').append(html);
          $('#modalEditFolder').modal('show');
          }
       });

The modal (modal.php):

<div class="modal-body">
    <?php include_once("/folder/edit.php"); ?>
</div>

The PHP file (edit.php):

<?php echo $_POST['pid']; ?>

How can I get both the modal and php form to get the PID variable?

2
  • What is the variable "obj"? Is that an element on the page? Commented Apr 22, 2014 at 20:29
  • It's part of right-click menu for jstree. Added into the code above. Commented Apr 22, 2014 at 20:32

1 Answer 1

1

try this :

$.ajax({
   type: "POST",
   url: "/view/folder/edit.php",
   cache: false,
   data: {'pid': obj.attr("id")}
}).done(function(html) {
   $('body').append(html);
   $('#modalEditFolder').modal('show');
});
Sign up to request clarification or add additional context in comments.

3 Comments

No, doesn't show the variable. What does $('body').append(html) do, if I may?
it will add what is returned from "/view/folder/edit.php" to the end of body tag
I actually combined my 3 files into 2 (so folder/edit.php + the modal) and it worked then. Accepting answer since technically the correct one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.