I have a form, and the URL is like this:
http://hostname/projectname/classname/methodname/variablename
And in my JavaScript, I fill an array like this:
var currentrelations = new Array();
$(".ioAddRelation").each(function(index) {
currentrelations[index] = $(this).html();
});
And this array has two values ['eeeeee','eeeeee']
So the url is:
http://localhost/Mar7ba/InformationObject/addIO/eeeeee,eeeeee
And in my PHP, in the class InformationObject, on the method addIO:
public function addIO($currentRelations =null) {
$name = $_POST['name'];
$type = $_POST['type'];
$concept = $_POST['concept'];
$contents = $_POST['contents'];
$this->model->addIO($name, $type, $concept, $contents);
if (isset($_POST['otherIOs'])) {
$otherIOs = $_POST['otherIOs'];
$this->model->addOtherIOs($name, $otherIOs);
}
$NumArguments = func_num_args();
if ($currentRelations!=null) {
$IOs = $_POST['concetedIOs'];
$this->model->setIoRelations($name,$IOs, $currentRelations);
}
exit;
include_once 'Successful.php';
$s = new Successful();
$s->index("you add the io good");
}
But when I print the array $currentRelations using this statement:
echo count($currentRelations)
The results was 1 not 2, and when I print the first element using thie statement echo $currentRelations[0] I get e not eeeeee
why is that? What is the solution? What am I doing wrong?
JSON.parse?JSON.stringifyto turn the array to a string and send it to the server. In PHP, you usejson_decodeto turn the string back into an array.$currentRelations = json_encode($currentRelations)?$currentRelationsis the stringeeeeee,eeeeee. Try$curRel = explode(',', $currentRelations);and thencount($curRel);.