我很困惑这个问题ajax发布数据,在localhost工作但共享主机无法正常工作。这是我的代码
<script type="text/javascript">
$(document).ready(function(){
$("#login").click(function(){
alert('asdf');
var page = "login";
var username = $("#username").val().trim();
var password = $("#password").val().trim();
$.ajax({
url:'pages/content/input_query.php',
type:'post',
data:{page:page,username:username,password:password},
success:function(response){
var msg = "";
if(response ==1){
window.location = "index.php?pages=home";
}else{
$("#result").html(response);
}
}
});
});
});
我的代码html是
<form role="form" action="pages/content/input_query.php" method="post">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="username" id="username" />
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" id="password" />
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
</div>
</div><!-- /.col -->
<div class="col-xs-4">
<button type="button" class="btn btn-primary btn-block btn-flat" id="login">Sign In</button>
</div><!-- /.col -->
</div>
</form>
我添加了代码 alert('asdf'),但每次点击按钮都没有警报消息。问题是什么。请帮我。我批评的每个答案
答案 0 :(得分:1)
你有没有在服务器上调用jQuery? 尝试从jQuery CDN调用。 使用此代码:
web
答案 1 :(得分:0)
尝试阻止#login元素的默认操作,当您传递POST类型时,必须使用大写字母。类似的东西:
<script type="text/javascript">
$(document).ready(function(){
$("#login").click(function(event){
event.preventDefault();
alert('asdf');
var page = "login";
var username = $("#username").val().trim();
var password = $("#password").val().trim();
$.ajax({
url:'pages/content/input_query.php',
type:'POST',
data:{page:page,username:username,password:password},
success:function(response){
var msg = "";
if(response ==1){
window.location = "index.php?pages=home";
}else{
$("#result").html(response);
}
}
});
});
});