我編寫了下面的例程來根據我的codeigniter應用程序的選定國家來檢索城市。如何不在js文件中硬編碼codeigniter鏈接
$(document).ready(function() {
$("select#cbo_country").change(function() {
$.post("http://localhost/main/index.php/city/get_data_by_country", {
int_country_id : $(this).val()
},
function(data) {
// some code here
},'json');
})
});
,你可以看到,我硬編碼的URL(HTTP://localhost/main/index.php/city/get_data_by_country),我知道這是一個不好的做法,但我不能幫助它。
有沒有一個不乾淨的方式來不硬編碼的網址?我曾經使用codeigniter的base_url(),但由於我將例程移動到一個js文件,我不能再使用該函數。
我忘了復出並挑選你的答案。我去選項2,因爲我不認爲base_url()將在.js文件上工作。謝謝。 – dqiu
選項1更好,它不是一個js文件,它是一個PHP文件。 – qwertzman