[英]Ajax Post Type will not send data to php page
I have the following form for users to reset their password it is within the file forgotten.php in the root directory. 我有以下表单供用户重置密码,该密码位于根目录中的忘记的文件php中。
<form id="pass_form" action="" method="post" name="pass_form">
<label>Username:</label>
<input type="text" class="blank" name="name" id="name" value="Trader Username" data-default="Trader Username" data-message="Please enter your username..."> *<br>
<input class="sub-btn" type="submit" value="Submit">
</form>
I would like to post the username to inc/sendreset.php so I have the following Ajax in js/scripts.js 我想将用户名发布到inc / sendreset.php,所以我在js / scripts.js中有以下Ajax
$("#pass_form").validator({
offset: [0, 354],
position: 'center left',
messageClass: 'conerror'
}).submit(function(e) {
if (!e.isDefaultPrevented()) {
var form = $(this);
var serdata = form.serialize();
$.ajax({
type: "POST",
url: "sendreset",
data: serdata,
cache: false,
success: function (html) {
log('inside ajax sendreset', this, arguments);
$('#pass_form').fadeOut(400,function(){
if (html=="0") {
} else {
$('#pass_form').html('<p>The password reset instructions have been sent. Please check your email.</p>');
}
$('#pass_form').fadeIn();
});
},
error: function (err) {
log('error inside ajax sendreset', this, arguments);
}
});
//$('#pass_form').fadeOut(400);
e.preventDefault();
}
});
However it does not seem to post the username into the file. 但是,似乎没有将用户名发布到文件中。 The inc/sendreset.php is as follows
inc / sendreset.php如下
<?php
require_once('./library.php');
require_once('./PHPMailer/class.phpmailer.php');
$Trader = new CompanyTrader();
$resetdata = $Trader->resetTrader($_POST['name']);
print_arr($resetdata);
//more php which isn't relevant
?>
I know the file inc/sendreset.php works as when I the file to use $_GET['name'] and i use inc/sendreset.php?name=username the array is returned for the relevant user. 我知道文件inc / sendreset.php的工作方式与当我使用$ _GET ['name']的文件并且使用inc / sendreset.php?name = username的方式为相关用户返回数组有关。 It does not work from forgotten.php using Ajax though.
但是,使用Ajax从forgotten.php无法正常工作。 Please help!
请帮忙!
i really think this is wrong: 我真的认为这是错误的:
url: "sendreset",
try with an relative or absolute url like http://mysite.com
尝试使用相对或绝对URL,例如
http://mysite.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.