对于本地主机上的ajax发布数据问题,我很困惑,但在共享主机上却无法正常工作。这是我的代码
<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'),但是每次单击按钮都没有警告消息。问题是什么。请帮我。我要求的每个答案
最佳答案
您在服务器上调用过jQuery吗?
尝试从jQuery CDN调用。
使用此代码:
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<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);
}
}
});
});
});
</script>
关于javascript - Ajax发布数据在共享主机上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44350185/