ここに投稿するのは初めてで、投稿を適切にフォーマットする方法がまだわかりませんが、これで終わりです。
したがって、基本的には、php ファイルを直接指定した場合にのみ、コードを機能させることができます。コントローラー内でメソッドを呼び出そうとしても、何も起こらないようです。
私のJavaScript:
$(document).ready(function() {
$(".guide_button").click(function(){
var id = $(this).text();
var data = {};
data.id = id;
$.getJSON("/guides/hehelol", data, function(response){
$('#test').text(response.id);
});
return false;
});
});
私のマークアップ:
<div id="content_pane">
<ul>
<li><a href="#" name="temp" class="guide_button">RL</a></li>
<li><a href="#">LG</a></li>
<li><a href="#">RG</a></li>
<li><a href="#">SG</a></li>
<li><a href="#">GL</a></li>
<li><a href="#">MG</a></li>
</ul>
</div>
<div class="description">
<h3>Description</h3>
<p id="test">This text area will contain a bit of text about the content on this section</p>
</div>
私のコントローラー:
<?php
class Guides extends CI_Controller {
public function Guides()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
}
public function index()
{
$this->load->view('guides_view');
$title = 'Some title';
}
public function hehelol() //The controller I am desperatly trying to call
{
$id = $_GET['id'];
$arr = array ('id'=>$id);
echo json_encode($arr);
}
}
それは私が何か間違ったことをした私のコントローラーかもしれません。このコードは、hehelol.php ファイルを作成し、このように直接参照する場合にのみ機能します。
$.getJSON("hehelol.php", data, function(response){
$('#test').text(response.id);
});
コントローラーを正しく動作させるために何をする必要があるか知っている人はいますか? 助けてください!:)