[英]Can someone help me with my ajax code?
I wanted to change the visibility of the thumbnail to visible right after when I click the button what should I do? 我想在单击按钮后立即将缩略图的可见性更改为可见,该怎么办? please help me on this one because I cannot figure it out by myself because I do not know so much about ajax and web programming.
请为我提供帮助,因为我自己无法弄清楚,因为我对ajax和Web编程了解不多。 Thanks in advance.
提前致谢。
function ha(){ $('#tabExe').click(function(event){ $.ajax({ url:'backEnd/ROOMS.php', success:function(result){ $('#room1').css({ // this is just for style "visibility" : "visible", }); } }); }); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <button style="border-radius:0px;" type="submit" name="tabExe" onClick="function ha();" id="tabExe" href="#Exec" class="btn btn-primary"> Executive Room </button> <div id = "rm1" class="col-xs-12 col-md-3"> <a id="room1" value="sa" href="#" class="thumbnail" style="visibility:hidden;"> <img class="img-responsive" src="../backEnd/res/img/login/roomActive.png" style="width:100px;"> </a> </div>
If you just need to show the thumbnail (and you're not concerned about the response), include a beforeSend
callback, like this: 如果您只需要显示缩略图(并且您不关心响应),则包括一个
beforeSend
回调,如下所示:
$('#tabExe').click(function(event){
$.ajax({
url:'backEnd/ROOMS.php',
beforeSend: function() {
$('#room1').css({ // this is just for style
"visibility" : "visible",
});
},
success:function(result){
}
});
});
This will call before making the ajax request. 这将在发出ajax请求之前调用。
success
and error
only are called when the request completes. 仅在请求完成时才调用
success
和error
。
Here's a fiddle demonstrating: 这是一个小提琴演示:
http://jsfiddle.net/jpattishalljr/rzr5mrL1/ http://jsfiddle.net/jpattishalljr/rzr5mrL1/
EDIT: IF you need the thumbnail to show when a response comes back, then you'll want to look into the ajax response and see why success
is not being called. 编辑:如果您需要缩略图来显示响应何时返回,那么您将需要调查ajax响应,看看为什么没有调用
success
。 One way to test is to add complete
, something like this: 测试的一种方法是添加
complete
,如下所示:
$('#tabExe').click(function(event){
$.ajax({
url:'backEnd/ROOMS.php',
beforeSend: function() {
$('#room1').css({ // this is just for style
"visibility" : "visible",
});
},
success:function(result){
},
complete: function(results) {
alert(results.status);
}
});
});
http://jsfiddle.net/jpattishalljr/rzr5mrL1/1/ http://jsfiddle.net/jpattishalljr/rzr5mrL1/1/
Should alert (404) 应该警惕(404)
Good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.