Javascript 我曾尝试使用ajax调用我的php函数,但我不知道代码有什么问题,因为它不起作用
尝试下面的代码,因为我刚刚从url中删除了http://文件。希望这有帮助Javascript 我曾尝试使用ajax调用我的php函数,但我不知道代码有什么问题,因为它不起作用,javascript,php,jquery,ajax,ajaxform,Javascript,Php,Jquery,Ajax,Ajaxform,尝试下面的代码,因为我刚刚从url中删除了http://文件。希望这有帮助 !-- Main Page Starts Here --> <section class="container"> <div class="row"> <div class="centerlogin"> <div class="frmlogin"> <form role="form" name="s
!-- Main Page Starts Here -->
<section class="container">
<div class="row">
<div class="centerlogin">
<div class="frmlogin">
<form role="form" name="signin" id="signin" method="post" action="#">
<div class="headtab"><h3>Login</h3></div>
<ul>
<li><i class="glyphicon glyphicon-user"></i> <input type="text" id="email" name="username" class="usern" placeholder="Enter Username"></li>
<li><i class="glyphicon glyphicon-lock"> </i><input type="password" id="pwd" name="password" class="passn" placeholder="Enter Password"></li>
<li><button class="subn" id="btnSubmit">Login</button></li>
</ul>
</form>
</div>
</div>
</div>
</section>
<!-- Main Page Ends Here -->
尝试下面的代码,因为我刚刚从url中删除了http://文件。希望这有帮助
!-- Main Page Starts Here -->
<section class="container">
<div class="row">
<div class="centerlogin">
<div class="frmlogin">
<form role="form" name="signin" id="signin" method="post" action="#">
<div class="headtab"><h3>Login</h3></div>
<ul>
<li><i class="glyphicon glyphicon-user"></i> <input type="text" id="email" name="username" class="usern" placeholder="Enter Username"></li>
<li><i class="glyphicon glyphicon-lock"> </i><input type="password" id="pwd" name="password" class="passn" placeholder="Enter Password"></li>
<li><button class="subn" id="btnSubmit">Login</button></li>
</ul>
</form>
</div>
</div>
</div>
</section>
<!-- Main Page Ends Here -->
Ajax调用中的Type属性定义了两次
请使用诸如Firebug之类的调试工具来调试xhr请求,以了解它们是否被发送。您还可以查看那些可能提示错误的请求的响应。Ajax调用中的Type属性定义了两次
请使用诸如Firebug之类的调试工具来调试xhr请求,以了解它们是否被发送。您还可以查看那些可能提示错误的请求的响应。在我将javascript文件的顺序更改为表单的html文件后,代码正在运行 我将javascript代码文件放在
//ajax calls start below
$(document).ready(function () {
$("#btnSubmit").click(function (e) {
e.preventDefault();
var email = $("#email").val();
var password = $("#pwd").val();
var pwd = $.md5(password);
auth(email, pwd);
});
});
//authenticate function to make ajax call
function auth(email, pwd) {
$.ajax
({
type: "POST",
url: "web/sign-in",
dataType: 'json',
type : "POST",
data: { email: email,pwd: pwd },
success: function (r) {
//console.log(r);
if(r.status == '0')
{
var sk=r.sk;
$.ajax({
type: "POST",
url: "secret/signin.php",
type : "POST",
data: { sk:sk},
success: function(r)
{
if(r == '0')
{
window.location.href = "main/index.php";
}
else
{
window.location.href = "main/login.php";
alert('Something Went Wrong.Please Try Again!');
}
}
});
}
else if(r.status == '401')
{
alert("Incorrect Email/Password");
$("#signin")[0].reset();
}
else
{
alert("User Doesn't exist");
$("#signin")[0].reset();
}
return false;
}
});
}
在我将javascript文件的顺序更改为表单的html文件后,代码就开始工作了 我将javascript代码文件放在
//ajax calls start below
$(document).ready(function () {
$("#btnSubmit").click(function (e) {
e.preventDefault();
var email = $("#email").val();
var password = $("#pwd").val();
var pwd = $.md5(password);
auth(email, pwd);
});
});
//authenticate function to make ajax call
function auth(email, pwd) {
$.ajax
({
type: "POST",
url: "web/sign-in",
dataType: 'json',
type : "POST",
data: { email: email,pwd: pwd },
success: function (r) {
//console.log(r);
if(r.status == '0')
{
var sk=r.sk;
$.ajax({
type: "POST",
url: "secret/signin.php",
type : "POST",
data: { sk:sk},
success: function(r)
{
if(r == '0')
{
window.location.href = "main/index.php";
}
else
{
window.location.href = "main/login.php";
alert('Something Went Wrong.Please Try Again!');
}
}
});
}
else if(r.status == '401')
{
alert("Incorrect Email/Password");
$("#signin")[0].reset();
}
else
{
alert("User Doesn't exist");
$("#signin")[0].reset();
}
return false;
}
});
}
它工作得很好。删除https-here-url:,哪些是脚本中使用的.js库?删除https-here-url:,哪些是脚本中使用的.js库?不起作用!你能分享网站文件和文件夹结构吗?然后我会在URL中为您做一个更改。我解决了这个问题,只需将我的jquery代码放在jquery库之后,现在它就可以工作了……它不工作了!你能分享网站文件和文件夹结构吗?然后我会在URL中为您做一个更改。我解决了它,只需将我的jquery代码放在jquery库之后,现在它正在运行……我使用firebug和console来发现问题,现在它是solvedi使用firebug和console来发现问题,现在它已经解决了