0

Ok, I know there were many of those but my code just won't work... I tried solutions found on Stack but still...

I would like to transfer my array built in jQuery to my php script that will compare it with other array etc.

My jQuery code looks like this:

$.post('rezultat.php',{wyb: JSON.stringify(wybrane)});

and in my rezultat.php file I try to decode it:

$wyb = json_decode($_POST['wybrane']);

I tried the $_POST method before, with no results. What am I doing wrong?

1
  • 8
    $_POST['wyb'], since that's what you're calling the field in the JS code. var_dump($_POST) will confirm that. Commented Nov 18, 2013 at 16:17

2 Answers 2

3

You need to use $_POST['wyb'] instead of $_POST['wybrane'] in your php script, since you used 'wyb' key in the array you created in javascript.

Sign up to request clarification or add additional context in comments.

Comments

0

You are calling the parameter with his Javascript name, try to call with the $_POST name:

$wyb = json_decode($_POST['wyb']);

5 Comments

Why was this voted down when it's essentially the same as the answer above?
Yeah, I tried that already. On my page I receive this: Notice: Undefined index: wyb in C:\xampp\htdocs\rezultat.php on line 3 where line 3 is of course $wyb = json_decode($_POST['wyb']);
Check your param before send, console.log(JSON.stringify(wybrane)); and var_dump($_POST) in the other side and check your values.
Does it matter that wybrane array is empty at first? User will fill it with his own values and finally hit the button in jQuery that will start the function that sends it to php file. So technically, when I load the site, this array is empty, right?
You mean sth like this: if(isset($_POST['wyb'])){ $wyb = json_decode($_POST['wyb']); foreach($wyb as $w) { echo $w; }} ? Cause it doesn't work. Sorry if I'm retarded :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.