Symfony and jQuery.data()
I have an ajax navigation system in my app. Each ajax link is of class ajax
and the page it needs to load is saved in an aurl
attribute, for example:
<a class="ajax" aurl="/user/posts/3/edit">Edit Post</a>
The aurl is given to the element using symfony's url_for
method in the server-side.
I thought about more elegant way of saving the element's aurl attribute, like jQuery.data()
, but how can i use it from the server side? creating a script after each element to set it's aurl
doesn't seem like a good solution..
Any ideas?
<a class="ajax" data-aurl="/user/posts/3/edit">Edit Post</a>
Then you can access it through .data('aurl')
if you use a recent jQuery version (1.5 or newer AFAIK).
However, why don't you simply set the href
(which should be set anyway) and then use $(this).attr('href')
to get the url and use e.preventDefault();
(with e
being the first argument of the click handler function) to prevent the link from loading without AJAX?
精彩评论