相关疑难解决方法(0)

如何不在js文件中硬编码codeigniter链接

我编写了下面的例程,根据我的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文件,我不再能够使用该函数.

javascript jquery codeigniter

3
推荐指数
1
解决办法
6116
查看次数

如何始终解析相对于我的Web应用程序根目录的URL?

我有一个Web应用程序,它是一个JavaScript文件,代码如下:

var arrowimages = { down: ['downarrowclass', 'images/AppNavDownArrow.gif', 23], right: ['rightarrowclass', 'images/AppNavRightArrow.gif'] }
Run Code Online (Sandbox Code Playgroud)

当我在我的Web应用程序的根目录时,对图像的引用按预期工作.当我浏览到我的应用程序中的子文件夹时,它会将相同的子文件夹添加到图像URL并且不加载.

如何在我的应用程序中的子文件夹中修改代码以便指向创建图像路径?

javascript asp.net url reference

1
推荐指数
1
解决办法
2052
查看次数

如何从AJAX请求中返回值?

我有一个函数,用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)

javascript ajax

0
推荐指数
1
解决办法
1063
查看次数

标签 统计

javascript ×3

ajax ×1

asp.net ×1

codeigniter ×1

jquery ×1

reference ×1

url ×1