Can anyone give me a better way (or best practice way) of doing the following in jQuery:
I have control elements on a page for example:
<input id="generate-log" /> Enter the id you wish to process
...
and a handler for the form change:
// the next line gets generated, just written here for simplicity
var url = '/report/log/XidX/csv';
$(function() {
$("#generate-log").change(function() {
var id = $(this).val();
var loadUrl = url.replace('XidX', id);
// ... do some ajax with loadUrl...
});
});
the url is generated as part of the template with id as XidX
The above works fine, but to me it seems that generating the url with XidX and then replacing it in JS seems a bit clumsy. Is there a neater way to do this or am I just being overly pedantic?
Thanks
Edit:
Thanks for comments. I think there is no right/wrong answer here.