codeigniter uri segment url追加到最后

时间:2012-06-18 04:14:15

标签: javascript uri segments

url:http://localhost/back-office/index.php/staff/shopping

当我在每个onchange事件上更改类别时,我希望网址应该像这样

http://localhost/back-office/index.php/staff/shopping/1
http://localhost/back-office/index.php/staff/shopping/2

因为我在变更事件上写了javascript

function cat()
{
    var x = document.getElementById('cat').value;   
    document.location = "shopping/" + x;


}


     <select name="cate" id="cat" onchange="cat()">
        <option value="0">Select Cateogry</option>
        <?php 
        foreach($get_cat as $category)
        {
            echo "<option value=$category->categoryid>$category->category</option>";            
        }
        ?>    
    </select> 

javscript有效,但是网址会像

一样被追加
http://localhost/back-office/index.php/staff/shopping/shopping/2

http://localhost/back-office/index.php/staff/shopping/shopping/shopping/shopping/shopping/shopping/1

在每个cagetory drop box onchange事件上,url会在最后添加这样的内容。

我怎么能解决这个问题

1 个答案:

答案 0 :(得分:1)

你需要专门编码你的网址..这个

function cat()
{
    var x = document.getElementById('cat').value;   
    url  = "http://localhost/back-office/index.php/staff/shopping/" + x;
    window.location = url;

}