views:

76

answers:

1

Hello,

I am having hell of a time trying to figure this one out. Maybe someone can help me here or point me in the right direction.

I have a jQuery UI dialog that pops up when user clicks on an image. The dialog displays a form with 2 drop down windows. "dept" and "group". Group drop down is disabled, until something is selected in the "dept" dropdown menu.

When user selects a department, I do a POST to php function and then enable and populate the group drop down. Simple enough...

<select name="dept" id="dept_select" onchange="getDeptGroups(this.value);">
 // Some data here
</select>

JS function:

function getDeptGroups(dept)
{
       // This alert works and displays department name.
       //alert(dept);

       $.post("/am/ldap/getDepartmentGroups.php", { 
              department: dept },
              function(data){
                    alert(data);
       });
}

and finally in php page i just do

<? print_r($_POST); ?>

and end up with empty array.

Array
(
)

This happens in both, Chrome and Firefox, however, FireBug clearly shows post data being submitted:

Screenshot of FireBug showing POST data

What am i doing wrong here?

A: 

First, verify that the PHP side of things is working as expected. Set up a static form that posts to that page and see what the output is:

<form action="/am/ldap/getDepartmentGroups.php" method="post">
  <select name="dept">
    <option value="extern">External</option>
    ...etc
  </select>
  <input type="submit" value="Submit">
</form>

If you still get a blank array as the output, then there is a problem in PHP and/or the server.

Otherwise, perhaps try using the jQuery ajax function, since calling post jsut calls that anyway:

$.ajax({
  type: 'POST',
  url: '/am/ldap/getDepartmentGroups.php',
  data: { department: dept },
  success: function(data) {
    alert(data);
  }
});

EDIT: Ah, you said in a comment you're using CodeIgniter. I believe CI removes the $_POST array, you'll need to use $this->input->post instead. To get your department variable you would write $this->input->post('department')

DisgruntledGoat
regular post with submit button works fine, but adding changing `$.post` to `$.ajax` does not change anything. I still get empty `POST`
solefald
`$_POST` works fine in CI, actually. I use it all the time. The reason i am not using `$this->input->post()` in this case is because it can only output individual values, while `$_POST` dumps the entire `POST` array.
solefald