简体   繁体   English

jQuery post()到php页面

[英]jQuery post() to php page

I'm learning php/javascript so don't smile... 我正在学习php / javascript,所以请不要微笑...

I try from page1.php to post 3 variables to page2.php. 我尝试从page1.php将3个变量发布到page2.php。 I'm not sure what's wrong... Here is the code (simplified mode): 我不确定这是怎么回事...这是代码(简化模式):

page1.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 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 }); 

Since you are learning, you might try to isolate problems by writing shorter chunks of code and seeing if they work first. 由于您正在学习中,因此您可以尝试通过编写较短的代码块并查看它们是否首先起作用来隔离问题。 In this case your first problem is an ordinary typo (test3=test3, instead of test3: test3) so your whole JS does not parse. 在这种情况下,您的第一个问题是普通的拼写错误(test3 = test3,而不是test3:test3),因此您的整个JS都不会解析。 You should be seeing the relevant error message in the firebug console (or chrome console). 您应该在Firebug控制台(或Chrome控制台)中看到相关的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM