Not receiving data in php codeigniter when sending ajax post


Allanz

I'm trying to send data by post using ajax (with codeigniter), I don't know why, but I'm not getting anything...

This is how I send it:

var sendData = $('#formContact').serialize();
$.ajax({
    type: 'POST',
    url: '<?php echo base_url()?>/intranet/update/updateProfile',
    data: sendData,
    dataType: 'json',
    success: function (data) 
    {
        console.log(data);
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
    }
});

Here is an example of my form:

<form id="formContact" action="update" method="POST">
    <input class="headInput" type="text" name="userName" value="Tito"/>
    <input class="headInput" type="text" name="userLastName" value="Lancreo"/>
    <input class="headInput" type="text" name="phone[]" value="666666"/>
    <input class="headInput" type="text" name="phone[]" value="111111"/>
    <input class="headInput" type="text" name="phone[]" value="222222"/>
</form>

When I debug it I always get 0...

[false, false, Array[0], false, null]

my controller:

$this->load->helper('form');
$this->load->library('form_validation');

//1 way
$ret=$this->input->post();

//2 way        
$return=$this->input->post(NULL, TRUE);

//3 way
$all=$_POST;
json_encode($all);

//4 way
$contact=$this->input->post("userName");

//return everything...
$var[0]=$return;
$var[1]=$contact;
$var[2]=$all;
$var[3]=$ret;
$var[4]=$data;
echo json_encode($var);

How can I fix this?

Allanz

solved!

The problem is not with replacing with:

serialize().replace(/%5B%5D/g, '[]');

But I think it's useful...

My problem is that I am using the internationalization library ( https://github.com/bcit-ci/CodeIgniter/wiki/CodeIgniter-2.1-internationalization-i18n ) and I have to add the language in the URL even if I change my routes.php

url: '<?php echo base_url()?>en/intranet/update/updateProfile'

thank you very much!

Related


Not receiving data in php codeigniter when sending ajax post

Allanz I'm trying to send data by post using ajax (with codeigniter), I don't know why, but I'm not getting anything... This is how I send it: var sendData = $('#formContact').serialize(); $.ajax({ type: 'POST', url: '<?php echo base_url()?>/intranet/u

Ajax is sending data but Php file is not receiving data

awtthem I've spent the past 10 days or so trying to figure this out and I'm still stuck. I'm making an online budgeting system that sends Javascript values via Ajax to PHP which then sends them to a database. this is my javascript code $.ajax({ url: 'yup.ph

CodeIgniter not receiving POST data

SuperiorREX I already have a Codeigniter based RESTful api service that performs basic CRUD operations against a mySQL database. Now I am trying to create a control panel using angularJS and Restangular. I make a POST request like this: HTML: <form ng-submit="

CodeIgniter not receiving POST data

SuperiorREX I already have a Codeigniter based RESTful api service that performs basic CRUD operations against a mySQL database. Now I am trying to create a control panel using angularJS and Restangular. I make a POST request like this: HTML: <form ng-submit="

Codeigniter not receiving POST data

Bart Bergmans I'm making a POST request to my website, but when I debug $_POSTand $this->input->post()both are an empty array. I have already global_xss_filteringset FALSE. I also put a debug line at the top of index.php, but that line also returns an empty $_

CodeIgniter not receiving POST data

SuperiorREX I already have a Codeigniter based RESTful api service that performs basic CRUD operations against a mySQL database. Now I am trying to create a control panel using angularJS and Restangular. I make a POST request like this: HTML: <form ng-submit="

Codeigniter not receiving POST data

Bart Bergmans I'm making a POST request to my website, but when I debug $_POSTand $this->input->post()both are an empty array. I have already global_xss_filteringset FALSE. I also put a debug line at the top of index.php, but that line also returns an empty $_

Ajax not sending data [Codeigniter]

Corentine Verpirat I'm having a problem with Ajax, indeed, I try to use Ajax to send the value to my upload function before submitting. However, when I check the $_POST array in the PHP code, only the value of the form is present, not from ajax, and I don't kn

Ajax not sending data [Codeigniter]

Corentine Verpirat I'm having a problem with Ajax, indeed, I try to use Ajax to send the value to my upload function before submitting. However, when I check the $_POST array in the PHP code, only the value of the form is present, not from ajax, and I don't kn

Ajax not sending data [Codeigniter]

Corentine Verpirat I'm having a problem with Ajax, indeed, I try to use Ajax to send the value to my upload function before submitting. However, when I check the $_POST array in the PHP code, only the value of the form is present, not from ajax, and I don't kn

Ajax not sending data [Codeigniter]

Corentin Verpillat I have a problem with ajax, indeed, I try to use ajax to send the value to my upload function before submitting. However, when I check the $_POST array in the PHP code, there is only the value of the form, not from ajax, and I don't know why

Ajax not sending data [Codeigniter]

Corentine Verpirat I'm having a problem with Ajax, indeed, I try to use Ajax to send the value to my upload function before submitting. However, when I check the $_POST array in the PHP code, only the value of the form is present, not from ajax, and I don't kn

Ajax not sending data [Codeigniter]

Corentine Verpirat I'm having a problem with Ajax, indeed, I try to use Ajax to send the value to my upload function before submitting. However, when I check the $_POST array in the PHP code, only the value of the form is present, not from ajax, and I don't kn

Sending data using POST via AJAX and PHP

Benjamin Oatmeal I have an object that I want to send in an AJAX request: function send_value() { $.ajax({ type: 'post', url: 'get.php', data: { source1: "some text", source2: "some text 2", uniI

Sending data using POST via AJAX and PHP

Benjamin Oatmeal I have an object that I want to send in an AJAX request: function send_value() { $.ajax({ type: 'post', url: 'get.php', data: { source1: "some text", source2: "some text 2", uniI

Sending data using POST via AJAX and PHP

Benjamin Oatmeal I have an object that I want to send in an AJAX request: function send_value() { $.ajax({ type: 'post', url: 'get.php', data: { source1: "some text", source2: "some text 2", uniI

Sending data using POST via AJAX and PHP

Benjamin Oatmeal I have an object that I want to send in an AJAX request: function send_value() { $.ajax({ type: 'post', url: 'get.php', data: { source1: "some text", source2: "some text 2", uniI

Sending data using POST via AJAX and PHP

Benjamin Oatmeal I have an object that I want to send in an AJAX request: function send_value() { $.ajax({ type: 'post', url: 'get.php', data: { source1: "some text", source2: "some text 2", uniI

Sending data with ajax but empty $_POST in PHP

User 4592302 I'm trying to save a div's data attribute into a variable PHP on click. So I use $.ajax to send data via POST, but it returns an empty array. However, the POST can be displayed with good data in the console. AJAX $('.get-thumbnail-id').click(funct

Sending data using POST via AJAX and PHP

Benjamin Oatmeal I have an object that I want to send in an AJAX request: function send_value() { $.ajax({ type: 'post', url: 'get.php', data: { source1: "some text", source2: "some text 2", uniI

PHP not receiving Ajax data

pattern Hello, overflowers! I can't seem to manage to send my Ajax data to my php page correctly, it used to work perfectly fine, but now it doesn't work. I'm getting the correct data through, but on console.logmy php page I'm getting an Undefined indexerror.

PHP returns no data when sending ajax request

beans, lentils When I send an ajax post request to my getMessages.php file it returns nothing. I've tried manually setting the array values and printing them in the console and that seems to work. get message.php <?php require_once "mysqli.php"; $data = arra

No data response when sending ajax request to php

Markop I want to send a json data to my php but when i access it to my php there is no response. this is my ajax request var project = {project:"A"}; var dataPost = JSON.stringify(project); $.ajax({ url: 'fetchDate.php', data: {myData: da

No data response when sending ajax request to php

Markop I want to send a json data to my php but when i access it to my php there is no response. this is my ajax request var project = {project:"A"}; var dataPost = JSON.stringify(project); $.ajax({ url: 'fetchDate.php', data: {myData: da

PHP returns no data when sending ajax request

beans, lentils When I send an ajax post request to my getMessages.php file it returns nothing. I've tried manually setting the array values and printing them in the console and that seems to work. get message.php <?php require_once "mysqli.php"; $data = arra

PHP mail() not working when receiving Ajax POST request

Pontiac I've set up a form that uses jQuery ajax to send a POST request to an external php file, which then sends an email. I get a 200 status code but no email. Here is jQuery: var ajaxSend = function(dataObj) { $.ajax({ type: 'POST',

PHP mail() not working when receiving Ajax POST request

Pontiac I've set up a form that uses jQuery ajax to send a POST request to an external php file, which then sends an email. I get a 200 status code but no email. Here is jQuery: var ajaxSend = function(dataObj) { $.ajax({ type: 'POST',

PHP mail() not working when receiving Ajax POST request

Pontiac I have setup a form that uses jQuery ajax to send a POST request to an external php file which then sends an email. I get a 200 status code but no email. Here is jQuery: var ajaxSend = function(dataObj) { $.ajax({ type: 'POST',

Php POST not receiving any data

Toon tree I'm new to php recently and now I'm developing a login form that has a registration page and a registration script to do all the database etc. But my $_POST doesn't work at all. I've tried searching online, confirmed that my xampp/php/php.ini setting