javascript - Post js array to php @jquery @codeigniter -
I have a PHP controller with the AGX post method (I'm using the codeigniter) to cross a JavaScript array I am trying. Data is being sent but $ _POST ['data'] is not known This code is:
JAVASCRIPT:
function update_order () {var ordre_column1 = $ (' # Column1 '). Sortable ('toArray'); Var data = serialize (ordre_column1); $ .post ('../../ controlleur_groupe_admin / ordre_box', data); My control: function ordre_box () {$ data = $ this- & gt; Input-> Post ('data') $ array = unserialize ($ data); Print_r ($ array); }
I did not get any returns in the firebug, I wonder if the content type is incorrect:
content-type application / x-www-form-urlencoded; Charset = UTF-8
Thank you.
To simplify the code:
Javascript:
function update_order () {var ordre_column1 = $ ('# column1'). Sortable ('toArray'); Var data = ordre_column1.toString (); $ .post ('../../ controlleur_groupe_admin / ordre_box', data); }
Controller:
function ordre_box () {echo $ _POST ['data']; FireBug says: Message: Undefined index: $ data
but the post exists: Parameters application / x-www-form- Urlencoded 131,126,125,156,154 Source 131,126,125,156,154
How do you know that the key is 'data', will not it be that you have gone into the serialized string? For example, if you have an array like this:
$ array ['value'] = 'hey!';
and you have serialized it and sent it to the controller, you will get that value in such a way:
$ this- > Input-> ( 'Values');
It's not what I think you're trying to do, but I may be wrong:
$ array = $ This- & gt; Input-> Post ('data'); Counterpart $ array ['value'];
To fix this, you can keep the JS array with another key data and then you can serial it.
< / Html>
Comments
Post a Comment