2015-11-05 38 views
3

我想加載簡單的codeignitier控制器,但沒有成功,我得到錯誤。JQuery不會加載明確的url?

它看起來像jquery加載不支持美麗/清晰的網址?這是可能的和如何?

當我嘗試使用相同的代碼加載某個文件時,它完美地工作,但是當我嘗試加載代碼簽名控制器函數時,我在控制檯中獲取404。

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#season").load('https://www.example.co/index.php/system/example'); 
     //i already tried without 'index.php' 
    }); 
</script> 

當我檢查確實使用一些簡單的文件讀取功能的工作原理,它完美的作品:

和控制器:

public function example(){ 
    echo "EXAMPLE"; 
} 

該鏈接存在,而不是404(當然沒有例子):

https://www.example.co/index.php/system/example

enter image description here

+0

你檢查你的路線 – Snm

+0

@Snm路線是正確的。我也嘗試使用base_url函數,結果是一樣的。 有可能通過加載函數加載漂亮的鏈接?我知道「醜陋」的網址有效,但如何使用漂亮鏈接? – DocNet

+0

你可以告訴我你是如何使用htaccess和路線 – Snm

回答

0

嘗試把它作爲

window.location.href = '<?php echo base_url('controller/method'); ?>' 
+0

你能給我完整的例子,我可以怎樣稱呼它? 當我嘗試它時,它將我重定向到/ system/example – DocNet

+0

系統是您的控制器,示例是方法? –

+0

是的,正確。 – DocNet

0

我解決它通過添加 '?'在index.php之前。 因此,這是結果:

<script type="text/javascript"> 
    var PI = { 

    onReady: function() { 
     $.ajax({ 
     type: 'GET', 
     url: '/index.php?/system/getseasons/SC0', 
     success: function (response) { 
      alert('success'); 
      $("#season").html(response); 
     }, 
     error: function(xhr, textStatus, error){ 
       console.log(xhr.statusText); 
       console.log(textStatus); 
       console.log(error); 
     } 


     }) 
    }, 

    }; 

    $(document).ready(PI.onReady); 

</script> 
+0

看起來您的重寫規則不正確,並且不會刪除'?'。看看[建議的格式](https://ellislab.com/codeigniter/user-guide/general/urls.html),並將它與你的won'.htaccess'進行比較。但之前,請嘗試直接進入瀏覽器時需要相同的URL。 –