我想通過AJAX從客戶端調用服務器功能。從JS到PHP的AJAX post方法 - 變量null
的index.php:
<?php
?>
<html>
<head>
...
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
...
console.log(position); // there IS a value! good!
console.log(result); // there IS a value! good!
jQuery.ajax({
type: "POST",
url: 'crud.php',
data: {functionname: 'insertLocation', arguments: [position, result]},
success:function(data) {
alert(data);
}
});
crud.php:
<?php
$position = $_POST["position"]; //NOTHING!
$result = $_POST["result"]; //NOTHING!
include ("insert.php");
switch($_POST["functionname"]){
case 'insertLocation':
insertLocation($position,$result);
break;
}
?>
insert.php
<?php
function insertLocation($position,$result){
...
}
?>
它傳遞到服務器端,當我失去了價值。我能夠記錄從JS的價值,但是當我登錄的PHP有空(或空字符串?)。也查詢數據庫的作品,但沒有插入任何值。
我初學網絡編程的,所以我提前異味道歉等
我認爲它是因爲你發送變量'位置'和'結果'在數組'參數'。我錯了嗎? –