CodeIgniter Forums

Full Version: Disallowed Key Characters.?array_emails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi;

I use ajax submit a form but I get the error


Quote:Disallowed Key Characters.?array_emails


Here is the code
PHP Code:
////
$("#save_now_button").click(function()
$.
post('<?php echo base_url("add_multiple_monitor_edit_access?"); ?>?' + $("#add_access").serialize(), {}, function (response) {$('#access_results_div').html(response);}));
//// 

This is the form
Code:
<form id="add_access" method="post">
  <input id="array_emails" name="array_emails" type="text">
  <div class="row" id="tr_1474294343512">
     <div class="col-md-5 section-header"><input style="border:none;  background:none; background-color: transparent;" name="email[]" id="email_1474294343512" value="[email protected]" type="text"></div>
     <div class="col-md-4 section-header"><input value="edit" name="edit_monitor_1474294343512" id="edit_1474294343512" type="checkbox">&nbsp;Edit</div>
     <div class="col-md-2 section-header"><input name="edit_monitor_1474294343512" id="monitor_1474294343512" value="monitor" type="checkbox">&nbsp;Monitor</div>
     <div class="col-md-1 section-header"><i class="fa fa-trash-o" aria-hidden="true" onclick="remove_email_row('tr_1474294343512', 'email_1474294343512')"></i></div>
  </div>
  <br>
</form>

And on the other page
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Add_multiple_monitor_edit_access extends CI_Controller {
 
 
 
public function index()
 {
 
print_r($_POST); 
 } 

Try this:

Code:
<head>

<script>
   var baseUrl = '<?php echo base_url(); ?>';
</script>

</head>

$.post(baseUrl + "add_multiple_monitor_edit_access/" + $("#add_access").serialize(), {}, function (response) {$('#access_results_div').html(response);}));
First, I'm going to reformat the JavaScript to attempt to make the source of the problem more obvious, though I did add the curly braces around the function definition (the omission of which should've caused a different error than the one described):
Code:
$("#save_now_button").click(function() {
    $.post(
        '<?php echo base_url("add_multiple_monitor_edit_access?"); ?>?' + $("#add_access").serialize(),
        {},
        function (response) {
            $('#access_results_div').html(response);
        }
    )
});

In the first argument to $.post(), you're getting a URL with ? at the end, then adding another ? in JavaScript.

I have a question, though. Why is it that so many people go through the trouble of using $.post(), then cram their data onto the end of the URL? I even checked the documentation, and this isn't done in the examples given for $.post(). That pair of empty curly braces you're passing as the second argument is where the data goes. It's so much easier to do this:

Code:
$("#save_now_button").click(function() {
    $.post(
        '<?php echo base_url("add_multiple_monitor_edit_access"); ?>',
        $("#add_access").serialize(),
        function (response) {
            $('#access_results_div').html(response);
        }
    )
});