简体   繁体   English

将JavaScript数组转换为PHP的另一页

[英]JavaScript Array to PHP on another page

I am trying to pass two arrays that I have created in JavaScript to another php page. 我试图将我在JavaScript中创建的两个数组传递给另一个php页面。 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: 当用户在“ process.php”上按下提交时,此函数称为:

$("#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. 这会将用户输入放入数组中,然后我尝试在最后使用$ .post方法,以便能够将数组传递到下一页,但是我不确定语法是否正确。

Then it is passed to the next file, "status.php," which at the beginning states: 然后将其传递到下一个文件“ status.php”,该文件的开头指出:

<?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... 删除该分号供初学者使用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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