Hello forum:
Hope someone can help me with this:
I am attempting to create my first json AJAX function.
I am attempting a json AJAX call to a PHP program but the PHP program is not receiving the data I am attempting to pass.
Here is the json AJAX function:
<script>
function parties() {
var someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';
$.ajax ({
type: "POST",
url: "redirect.php",
data: someJSON,
cache: false,
success: function(){
alert("AOK");
}
} );
}
</script>
Here is my PHP redirect,php program:
<?php
$someArray = json_decode($_POST['someJSON'], false);
print_r($someArray);
foreach ($someArray as $key => $value) {
$name = $value["name"];
$gender = $value["gender"];
echo $name . " " . $gender . "<br>";
}
exit();
?>
Program redirect,php executes but no data is being received by the $POST in it.
(the print_r function displays nothing),
The AJAX success function shows AOK.
Must be an error in my AJAX call but I can't find it.
Hope someone can help!
Larry
Hope someone can help me with this:
I am attempting to create my first json AJAX function.
I am attempting a json AJAX call to a PHP program but the PHP program is not receiving the data I am attempting to pass.
Here is the json AJAX function:
<script>
function parties() {
var someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';
$.ajax ({
type: "POST",
url: "redirect.php",
data: someJSON,
cache: false,
success: function(){
alert("AOK");
}
} );
}
</script>
Here is my PHP redirect,php program:
<?php
$someArray = json_decode($_POST['someJSON'], false);
print_r($someArray);
foreach ($someArray as $key => $value) {
$name = $value["name"];
$gender = $value["gender"];
echo $name . " " . $gender . "<br>";
}
exit();
?>
Program redirect,php executes but no data is being received by the $POST in it.
(the print_r function displays nothing),
The AJAX success function shows AOK.
Must be an error in my AJAX call but I can't find it.
Hope someone can help!
Larry
Comment