[英]jQuery Ajax call doesn't seem to work
我试图用jQuery Ajax调用一个页面,然后显示一个简单的响应(不管它是否起作用),但是似乎没有完成任何事情。 在FireBug中,我什至都不会出错。 我在这里做错了什么?
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
$('.doit').click(function (e) {
e.preventDefault();
$.ajax({
url: "https://www.domain.com/page.php?do=it",
type: "GET"
success: function (data) {
$(".result").html('<strong>Done!</strong>');
},
error: function (xhr, ajaxOptions, thrownError) {
$(".result").html('<strong>Houston, we have a problem.</strong>');
},
timeout: 15000
});
});
</script>
<a href="" class="doit">Do it</a>
<div class="result"></div>
type: "GET"
后,您错过了逗号。 另外,如@blex在评论中所述,您应将绑定放在ondomready上下文中,以确保绑定之前已加载元素。
$(function(){
$('.doit').click(function (e) {
e.preventDefault();
$.ajax({
url: "https://www.domain.com/page.php?do=it",
type: "GET",
success: function (data) {
$(".result").html('<strong>Done!</strong>');
},
error: function (xhr, ajaxOptions, thrownError) {
$(".result").html('<strong>Houston, we have a problem.</strong>');
},
timeout: 15000
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.