我编写了下面的例程来根据我的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