Php Jquery$.post发行
我想将我的数据发布到login.php页面。但问题是Php Jquery$.post发行,php,javascript,jquery,Php,Javascript,Jquery,我想将我的数据发布到login.php页面。但问题是$.post()不起作用。告诉我这个代码的错误 /includes/login.page(这是一个灯箱) /login.php 请帮助我查找此代码的错误。您需要尝试使用POST,因为您使用的是$。POST不是$。获取 if(isset($_POST['email'])){ $email = $_POST['email']; echo $email; } 此外,您还需要防止提交操作,如 $(document).ready(fun
$.post()
不起作用。告诉我这个代码的错误
/includes/login.page(这是一个灯箱)
/login.php
请帮助我查找此代码的错误。您需要尝试使用
POST
,因为您使用的是$。POST
不是$。获取
if(isset($_POST['email'])){
$email = $_POST['email'];
echo $email;
}
此外,您还需要防止提交操作,如
$(document).ready(function(){
$("#forgot-username-form").submit(function(e) {
e.preventDefault(); // Prevent Here
var email = $("#user-email").val();
alert(email);
$.post("login.php",{email:email},function(result){
alert(result);
});
return false;
});
});
试试这个
if(isset($_POST['email'])){
$email = $_POST['email'];
echo $email;
}
如果您想使用$\u GET
方法,那么可以这样尝试
脚本
$.get("login.php",{email:email},function(result){
alert(result);
});
PHP页面login.PHP
if(isset($_GET['email'])){
$email = $_GET['email'];
echo $email;
}
您所做的是正确的,您只需要在脚本中进行更改
$(document).ready(function(){
$("#forgot-username-form").submit(function(e) {
e.preventDefault()
var email = $("#user-email").val();
alert(email);
$.post("login.php",{email:email},function(result){
alert(result);
});
});
});
在提交函数中为事件添加参数e,并通过e.preventDefault函数防止其默认行为。请尝试以下方法:
$.post("login.php",{'email':email},function(result){
alert(result);
});
我已经做了更改:我刚刚引用了您的post数据对象的密钥。
您将电子邮件值分配给post数据对象的做法是错误的。现在,您上次的编辑,即在login.php
中将$\u GET
更改为$\u post
,使所有答案都不正确。@vinodhikary-是的,这是一个错误。我尝试使用GET,但发现了相同的结果:(
if(isset($_POST['email'])){
$email = $_POST['email'];
echo $email;
}
$.get("login.php",{email:email},function(result){
alert(result);
});
if(isset($_GET['email'])){
$email = $_GET['email'];
echo $email;
}
$(document).ready(function(){
$("#forgot-username-form").submit(function(e) {
e.preventDefault()
var email = $("#user-email").val();
alert(email);
$.post("login.php",{email:email},function(result){
alert(result);
});
});
});
$.post("login.php",{'email':email},function(result){
alert(result);
});