I have a site developed in codeigniter.
In many page of my site I have more equal function javascript/jquery with some string in PHP like this:
function change_city_by_nation(nation_id){
var site_url_city ="<?php echo(site_url('/backend/city/get_city_by_nation_id')); ?>";
$.ajax({
url: site_url_city,
async: false,
type: "POST",
data: "nation_id="+nation_id,
dataType: "html",
success: function(data) {
$('#city').empty();
$(data +' option').each(function(index){
$('#city').append($(this).html());
});
$('#city').prepend("<option value='0' selected='selected'>Tutte le città</option>");
}
});
}
Where is the best place to collect all this javascript function with some string in php?
- JS file (but I have to pass the php string when I call it)
- Helper (but how?)
- file php where declare the function JS like common.php(but where to put it and how to call it?)
Have you some solution for my scope? Thanks