mOr*_*off 29 ajax anchor jquery hyperlink
我几乎永远不会玩客户端的东西,这可能是一个简单的任务就是踢我的屁股:)
我有一些链接.OnClick我想阻止默认操作,捕获其href url,向该URL提交ajax GET,并简单地alert()
使用结果...但我甚至无法超越起始线:)
播放时间的示例锚点:
<a class="asynch_link" href="good/1.html">Click Here</a>
<a class="asynch_link" href="good/2.html">Click Here</a>
Run Code Online (Sandbox Code Playgroud)
现在,我已经对SO上的类似请求提出了一些建议,但链接仍然导致浏览器导航到href url.
即使只是
<script type="text/javascript">
$('a').click(function (event)
{
event.preventDefault();
//here you can also do all sort of things
});
</script>
Run Code Online (Sandbox Code Playgroud)
...链接仍然导航到另一页.
我有点像和婴儿在这里:)
任何和所有帮助将深表感谢.
而且,是的,我AM包括jQuery的:)
<script src="//67.20.99.206/javascripts/jqueryCountdown/1-5-11/jquery.countdown.js" type="text/javascript" charset="utf-8"></script>
mOr*_*off 39
$('a').click(function(event) {
event.preventDefault();
$.ajax({
url: $(this).attr('href'),
success: function(response) {
alert(response);
}
});
return false; // for good measure
});
Run Code Online (Sandbox Code Playgroud)
cod*_*biz 19
试试这个
$('a').click(function (event)
{
event.preventDefault();
var url = $(this).attr('href');
$.get(url, function(data) {
alert(data);
});
});
Run Code Online (Sandbox Code Playgroud)
这里的问题是事件没有附加到您的元素,因为它们没有绑定在 DOM 就绪事件中。尝试将您的事件包含在 DOM 就绪事件中,如果有效,您将看到警报
<script>
$(function() {
$('a').click(function(event) {
event.preventDefault();
alert('fff')
//here you can also do all sort of things
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
之后发送 Ajax 请求并在 Success 回调函数中提交表单。
<script>
$(function() {
$('a').click(function(event) {
event.preventDefault();
$.ajax({
url: 'url',
dataType :'json',
data : '{}',
success : function(data){
// Your Code here
$('#form').submit();
}
})
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
91571 次 |
最近记录: |