0

The issue is: It loads the selected index value alright in the first environement.

It does not send it in the second, MVC codeigniter. The controller does not get the selected index that before load did send.

1st one WORKS: Look how easy is to understand.

//jquery code for source list
$(document).ready(function()
      {
        $('#sel_pais').change(function()
             {
              if ($(this).val()!='')
             {
            $("#sel_source").load("includes/getchilds5.php",{pais_id: $(this).val()});
             }
                 });

    });  // end of first function

=========================================================
getchilds5.php file

if(isset($_REQUEST['pais_id']) && !empty($_REQUEST['pais_id'])) {
    $result = mysql_query("select * from tabla_from where pais_id='".$_REQUEST['pais_id']."' ");
    if(mysql_num_rows($result) > 0) {
        echo '<option value="">Select</option>';
        while($row = mysql_fetch_assoc($result)) {              
                echo '<option value="'.$row['id_from'].'">'.$row['from_name'].'</option>';
        }
    } else {
        echo '<option value="">Select</option>';
    }
}  # end of IF ISSET FOR PAIS

======= Now MVC It does not work, because the controller is not getting the value:

$(document).ready(function()
        {
         $('#country').change(function() 
                 {
                  if ($(this).val()!='') 
                      {
                       $("#source").load("/CI-3/application/controllers/control_form.php/",{pais_id: $(this).val()},  

                      }

                  });

        });  // end of first function
</script>


============================================================



        <?php echo form_open('control_form/add_all'); ?>
       <label for="country">Country<span class="red"></span></label>
        <select id="country" name="country">
            <option value="">Select</option>
            <?php

                foreach($result as $row)
                {
                echo '<option value="' . $row->pais_id . '">' . $row->pais_name . '</option>';
                }

            ?>
        </select>

        <label for="source">Source Language<span class="red"></span></label>
        <!--this will be filled based on the tree selection above-->
        <select id="source" name="source"> 
            <option value="">Select</option>

           <?php
===============================================================

The controller would do this:

 $pais_id = $this->input->get_post('country', TRUE); # but I am not getting anything

but it gets an empty object

  • 3
    What is the question? What MVC framework are you using? What is happening here? Anyhow, you should probably narrow down the problem before posting to Stack. – frnhr Aug 13 '12 at 15:59
  • What error message are you getting, if any? If none, is error reporting on? Do you have anything from Firebug? Have you done any due diligence before asking a question with large blocks of code that mean nothing to us and are mere snippets that on their own do nothing? – Andrew Aug 13 '12 at 16:19
  • Codeigniter. What happens is that the load does pass the value in the first environment but does not pass it in the second one, the MVC. The controller is not getting the value. I have pinpointed to it, excluded totally any model or controller bug. It is the bloody jquery that is driving me nuts – iaintunderstand Aug 13 '12 at 16:54

1 Answers1

1

It looks you you're trying to get data from POST request but you're sending it as GET. jQuery's $.load performs GET request and as manual says, it is equal to

$.get(url, data, success)

In your first example you used $_REQUEST to get form data, but in second it looks like you explicitly use $_POST array which is empty in case of using $.load.

You can find out how to use either whole $_REQUEST or get data from $_GET array.

It also looks like you have names mismatch. In jQuery you use pais_id but in MVC you're getting it as country which of course will be not found.

UPD: The strikethrough text left here for historical reason. It has no relation to the original topic as we cleared in chat discussion.

UPD2: Links that might help:

Community
  • 1
  • 1
zysoft
  • 2,268
  • 1
  • 16
  • 21
  • thanks but in anyhow I did try this: $pais_id = $this->input->get_post('country', TRUE); which looks for both. It is a mistery why it passes it perfectly on the first one and not in the MVC – iaintunderstand Aug 13 '12 at 16:55
  • @iaintunderstand, try var_dump on $_GET and $_POST separately to see if the parameter really comes in. – zysoft Aug 13 '12 at 16:58
  • I did and it gives false boolean, which means that there is no value being passed. In MVC it is equivalent to isset, so it is as if it were not set – iaintunderstand Aug 13 '12 at 16:59
  • 1
    @iaintunderstand, I've updated my answer. I think you're just sending parameter with different name than you're getting in controller. – zysoft Aug 13 '12 at 17:03
  • ah well, country vs pais_id. I have tried different combinations, it is supposed to be the option value that needs to be sent – iaintunderstand Aug 13 '12 at 17:03
  • 1
    you send it as `{pais_id: $(this).val()}` which will become `http://....../?pais_id=some_val`. But in controller you do `$pais_id = $this->input->get_post('country', TRUE);`. So you're sending param named `pais_id` but retrieving it as `country` – zysoft Aug 13 '12 at 17:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15279/discussion-between-iaintunderstand-and-zysoft) – iaintunderstand Aug 13 '12 at 17:07