我编写了下面的例程,根据我的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');
})
});
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我对网址进行了硬编码(http://localhost/main/index.php/city/get_data_by_country),我知道这是一个不好的做法,但我无法帮助它.
有没有一个很好的干净方法来不硬编码网址?我以前使用codeigniter的base_url(),但由于我将例程移动到js文件,我不再能够使用该函数.
我有一个Web应用程序,它是一个JavaScript文件,代码如下:
var arrowimages = { down: ['downarrowclass', 'images/AppNavDownArrow.gif', 23], right: ['rightarrowclass', 'images/AppNavRightArrow.gif'] }
Run Code Online (Sandbox Code Playgroud)
当我在我的Web应用程序的根目录时,对图像的引用按预期工作.当我浏览到我的应用程序中的子文件夹时,它会将相同的子文件夹添加到图像URL并且不加载.
如何在我的应用程序中的子文件夹中修改代码以便指向创建图像路径?
我有一个函数,用var
关键字声明一个变量.然后它启动一个AJAX请求来设置变量的值,然后从该函数返回该变量.
但是,我的实现失败了,我不知道为什么.
这是代码的简化版本;
function sendRequest(someargums) {
/* some code */
var the_variable;
/* some code */
request.onreadystatechange =
//here's that other function
function() {
if (request.readyState == 4) {
switch (request.status) {
case 200:
//here the variable should be changed
the_variable = request.responseXML;
/* a lot of code */
//somewhere here the function closes
}
return the_variable;
}
var data = sendRequest(someargums); //and trying to read the data I get the undefined value
Run Code Online (Sandbox Code Playgroud)