[jQuery] Server Side programming and JQuery best practice
Hi all.
What is the best way to pass "parameters" from the PHP script that
generate the page to the Javascript/JQuery functions that enhance the
page ?
In my page there are several element that trigger an ajax request and
show the result in a box. Of course each ajax request has a different
url to load.
how should i tell my js function which url to load ?
the url is just an example, there many different data i would like to
pass to my js functions.
I have done this in a couple of way, but i'm sure there are (much)
better ways ...
1. onclick
<span onlick="loadAjaxContent('/makeForAjax1.php')"
class="preview_button">CLICKME 1</span>
<span onlick="loadAjaxContent('/makeForAjax2.php')"
class="preview_button">CLICKME 2</span>
2. putting data in an hidden element
<span class="preview_button">
<span class="preview_url" style="display:none;">/makeForAjax1.php</
span>
CLICKME 1</span>
<span class="preview_button">
<span class="preview_url" style="display:none;">/makeForAjax2.php</
span>
CLICKME 2</span>
$(document).ready(function(){
$('.preview_button').click(function(e){
var url = $('#' + this.id + ' > .preview_url').html();
loadAjaxContent(url);
});
});
});
Thanks
Massimo