文字列「hello」も割り当てている test_string という変数があります。
var test_string = "hello";
そして、私が試した1つの方法でPHPページに投稿したい:
$.post('php_page.php', test_string);
私が使用するphp_page.phpで:
$new_var = $_POST['test_string'];
echo $new_var;
そして結果が出ません。$.post() で何が欠けていますか?
文字列「hello」も割り当てている test_string という変数があります。
var test_string = "hello";
そして、私が試した1つの方法でPHPページに投稿したい:
$.post('php_page.php', test_string);
私が使用するphp_page.phpで:
$new_var = $_POST['test_string'];
echo $new_var;
そして結果が出ません。$.post() で何が欠けていますか?
これを試して - -
$.post('php_page.php', {test_string:test_string});
そして私に知らせてください
私の作業コードを編集---
test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function handle(){
var test_string = "hello";
$.post('myphp.php', {'test_string':test_string},
function (result){
$("span").html(result);
});
}
</script>
</head>
<body>
<input type="button" onclick="handle();" value="Click" />
<span></span>
</body>
</html>
myphp.php
<?php
$new_var = $_POST['test_string'];
echo $new_var;
swapnesh が示すように$.post、2 番目のパラメーターとしてオブジェクトを期待することが不足しています。
$.post('php_page.php', { objkey : objval });
次に、PHP で次のように取得します。
$val = $_POST['objkey'];