簡體   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