如何将数据添加到<a> tag for use in Ajax Requests?</a>

时间:2010-03-02 13:21:49

标签: html ajax

我希望看到类似这样的链接:Call to Action。但是,如果javascript没有完全加载并且用户点击该链接,它们将被重定向到一个PHP脚本,它会吐出json。或者,我可能会采取行动呼吁的方式。

这是处理这种情况的最佳做法吗?

3 个答案:

答案 0 :(得分:1)

最简单的解决方案是使用Javascript将数据放在那里,然后没有时间不匹配。

<a id="link123" href="#">Call to Action</a>

,比方说,jQuery:

$(function() {
  $("#link123").click(function() {
    // get JSON, put the address ehre
  });
});

答案 1 :(得分:0)

我想我将使用jquery的元数据插件。

http://plugins.jquery.com/project/metadata

为什么这是一个糟糕的想法?

答案 2 :(得分:0)

理想情况下,link to a document which is the same as the current document would be after the transformation

听起来你已经覆盖了正常的链接操作,所以(就客户而言)你可能只需要做一些事情,比如在通过XHR运行之前将&type=json添加到URL。