0

Possible Duplicate:
Passing jquery variable with json

I am trying to pass a jquery variable from a view to my controller using this code

var str = 'Some data i need';


    $.post('Configs/', {data : str});

and then I am retrieving it in my controller with this code.

if($this->request->is('post'))
    {
       $value = $_POST['data'];

       if($value == null)
       {
           $this->Session->setFlash('null');
       }
       else
       {
        foreach($value as $v)
        {
            $this->Session->setFlash($v);       
        }
       }
    }

I can retrieve the array but when I try to iterate through $value all it prints out is the word 'Array'.

thanks for any help in advance.

Community
  • 1
  • 1
Schokea
  • 708
  • 1
  • 9
  • 28
  • Instead of `$_POST['data']` use $this->request->params. This might help you to achieve the same. – Arun Jain Aug 21 '12 at 11:18
  • No this just returns blank I just want to get the values from the string so i can write it to a text file but its after becoming a nightmare. – Schokea Aug 21 '12 at 11:57
  • You need to log what you're submitting to know where the error is - i.e. `debug($_POST['data']); die;` – AD7six Jan 15 '13 at 20:12

1 Answers1

0

Pass data as json string and in your controller convert this string into php array using json_decode()

EbinPaulose
  • 1,129
  • 3
  • 14
  • 26
  • Ye I have tried that but i keep getting the error: json_decode() expects string to be passed in but is getting an array? – Schokea Aug 21 '12 at 10:36