簡體   English   中英

jQuery post()到php頁面

[英]jQuery post() to php page

我正在學習php / javascript,所以請不要微笑...

我嘗試從page1.php將3個變量發布到page2.php。 我不確定這是怎么回事...這是代碼(簡化模式):

page1.php

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>  
</head>
<body>
<script type="text/javascript">
window.onload = post_text;
function post_text() {
test1="111";
test2="222";
test3="333";
$.post("page2.php", { test1:test1 , test2:test2, test3=test3 });
}
</script>
</body>
</html>

page2.php

<?php
$a=$_POST['test1'];
$b=$_POST['test2'];
$c=$_POST['test3'];
echo $a.$b.$c;
?>
$.post("page2.php", { test1:test1 , test2:test2, test3:test3 }); 

由於您正在學習中,因此您可以嘗試通過編寫較短的代碼塊並查看它們是否首先起作用來隔離問題。 在這種情況下,您的第一個問題是普通的拼寫錯誤(test3 = test3,而不是test3:test3),因此您的整個JS都不會解析。 您應該在Firebug控制台(或Chrome控制台)中看到相關的錯誤消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM