[英]How to display POST values which are coming from javascript XMLHttpRequest() in php
[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.