如何在点击事件上调用jQuery AJAX? [英] How to call jQuery AJAX on click event?

查看:86
本文介绍了如何在点击事件上调用jQuery AJAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个jQuery模型.

I made a jQuery model.

我正在尝试在该模型内部使用AJAX填充数据.

Am trying to populate data using AJAX inside that model.

我得到一个ID,并希望使用AJAX填充数据.

I am getting an id and using that I want to populate data using AJAX.

如何在点击事件中调用AJAX?

How should I call AJAX on click event?

打开或加载模型时还有其他事件吗?

Is there any other event when the model is opened or loaded?

模型只是div的显示和隐藏.

The model is just the showing and hiding of div.

推荐答案

只需使用:

JS:

$(document).ready(function(){
  $('a.pop').click(function() { 
    var popID = $(this).attr('rel');
    $.get('content.php', { ref:popID }, function(data) {
       $(popID+'Container').html(data);
       $(popID).dialog();
       alert('Load was performed.');
    });
    return false; // prevent default
  });
});

HTML:

<div id="example" class="flora" title="This is my title">
    I'm in a dialog!
    <div id="exampleContainer"></div>
</div>
<a href="#" id="clickingEvent" class="pop" rel="example">click to launch</a>

它没有经过测试,但是据我所知,它应该可以工作...

It is not tested, but as I see it, it should work...

这篇关于如何在点击事件上调用jQuery AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆