简体   繁体   中英

JavaScript Array to PHP on another page

I am trying to pass two arrays that I have created in JavaScript to another php page. I have researched this and I don't know what I am doing wrong. I have been following many forums and tutorials but I can't seem to get mine to work. I have a form which you can add additional lines which is why I have arrays. When the user presses submit on "process.php," this function is called:

$("#submit").click(function() {
    var accosArray = new Array();
    accomp = $("#TextBoxDiv1 textarea[name=sacco]").val();
    accosArray.push(accomp);
    alert(accosArray[0]);
    for (var i = 2; i < counter; i++) {
        accomp = $("#TextBoxDiv1" + i + " textarea[name=sacco]").val();
        accosArray.push(accomp);
        alert(accosArray[i - 1]);
    }
    var tasksArray = new Array();
    taskSelect = $("#TextBoxDiv1 select[name=lstDropDown_A]").val();
    if (taskSelect == "") {
        //If user entered a task
        taskOther = $("#TextBoxDiv1 input[name=textboxoption_A]").val();
        tasksArray.push(taskOther);
        alert(tasksArray[0]);
    } else {
        tasksArray.push(taskSelect);
        alert(tasksArray[0]);
    }
    for (var i = 2; i < counter; i++) {
        taskSelect = $("#TextBoxDiv1" + i + " select[name=lstDropDown_A]").val();
        if (taskSelect == "") {
            //If user entered a task
            taskOther = $("#TextBoxDiv1" + i + " input[name=textboxoption_A]").val();
            tasksArray.push(taskOther);
            alert(tasksArray[i - 1]);
        } else {
            tasksArray.push(taskSelect);
            alert(tasksArray[i - 1]);
        }
    }
    $.post('127.0.0.1/Working Files/Best Files/In Progress/status.php';, {
        task: tasksArray
    }, function(result) {
        alert(result[0]);
    }, 'json');
});

This puts the user inputs into the arrays and then I try to use the $.post method at the end in order to be able to pass the arrays to the next page but I am not sure if the syntax is correct.

Then it is passed to the next file, "status.php," which at the beginning states:

<?php
 session_start();
 $task=$_POST['task'];
 echo json_encode($task);
?>

The echo shows as "null."

Please let me know what I am doing wrong!

Thanks in advance!!

Looks like a rogue semicolon at the very least:

$.post('127.0.0.1/Working Files/Best Files/In Progress/status.php';

Remove that semicolon for starters...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM