【发布时间】:2016-03-02 20:18:33
【问题描述】:
到目前为止,我一直在编写一些代码,并且已经进行了一段时间的故障排除,我很确定我的语法是正确的。我一直不得不解决一个损坏的测试环境,所以我不能使用正常的断点在后端进行测试。
我在javascript中有以下功能:
function ns_submit_form_inpage(path, data){
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
alert("Message Sent");
}
}
request.open('POST', path, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
var temp_string = array_to_string(data);
alert("data:"+ temp_string);
request.send(data);
}
以及PHP中的以下代码:
<?php
mail("my_email@example.com", "Array: ". print_r($_POST, true), "From:test@example.com");
?>
我调用函数,将路径与数组一起传入。我收到一封电子邮件和一个适当的警报,所以我知道我的函数被调用并且正确的文件被命中并触发。 A 还知道,在我发送数据之前,它们的数据正确地位于键控数组中(例如 first_name::bob、last_name::doe)。但是,我收到的电子邮件显示“Array: Array()”并通过我的“Message Sent”警报进行确认。
我已经缩小了我认为我的错误可能出现的范围,而且我几乎没有剩下任何东西,感觉就像阵列正在消失在互联网的以太中。
【问题讨论】:
标签: javascript php arrays post xmlhttprequest