繁体   English   中英

使用XMLHttpRequest从Javascript到PHP POST大数组

[英]POST large array from Javascript to PHP with XMLHttpRequest

我正在尝试通过PHP将大型数组从Javascript发送到mySQL。 我正在尝试POST,但以下操作无效。 http.onreadystatechange中的“警报”会弹出并显示仅包含以下代码。 代码看起来很简单。 任何帮助表示赞赏。

<?php 

if (isset($_POST['params'])) {
echo 'YES isset';
$phpobj = ($_POST['params']);
echo $phpobj;

}else{
echo 'No isset';
}

?>


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
http=new XMLHttpRequest();
}else{// code for IE6, IE5
http=new ActiveXObject("Microsoft.XMLHTTP");
}

var url = "PostArray.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
    alert(http.responseText);
}
}
http.send(params);

</script>

  1. 您要传递的数据中没有变量称为params,只有lorem和name
  2. 您甚至都不会发布它,因为您尚未将变量params(在javascript中)传递给http对象

暂无
暂无

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

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