php – Jquery .ajax method =“post”,但$_POST为空
发布时间:2020-12-13 16:24:05 所属栏目:PHP教程 来源:网络整理
导读:$就({ 方法:“post” ,url:“save.php” ,data:“id = 453 action = test” ,beforeSend:function(){ },complete: function(){ },success: function(html){ $("#mydiv").append(html); }}); 我已经将方法类型设置为post,但是在Save.php中,我只是在$_GET
$就({
方法:“post” ,url:“save.php” ,data:“id = 453& action = test” ,beforeSend:function(){ },complete: function(){ },success: function(html){ $("#mydiv").append(html); } }); 我已经将方法类型设置为post,但是在Save.php中,我只是在$_GET或$_REQUEST中获取值,但不能在$_POST中获取值. 我的表单看起来像 <form method="post" id="myform" action="save.php"> 它不工作,环顾四周,并在Google上尝试添加enctype <form method="post" id="myform" action="save.php" enctype="application/x-www-form-urlencoded"> 但仍然$_POST为空? 我该如何让它工作?谢谢.
而不是方法:“post”你需要使用type:“POST”
所以这应该工作没有任何改变你的表单HTML: $.ajax({ type: "POST",url: "save.php",data: "id=453&action=test",beforeSend: function(){ },success: function(html){ $("#mydiv").append(html); } }); 不知道为什么它不工作,但这对我有用: save.php <?php print_r($_POST); file.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(function() { $('input').click(function() { $.ajax({ type: "POST",beforeSend: function(){ },complete: function(){ },success: function(html){ alert(html); } }); }); }); </script> </head> <body> <div id="main"><input type="button" value="Click me"></div> </body> </html> 你的错误必须在别的地方. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |