0

私のajaxコードに問題があります。ajaxでクリック時にスパン内の数を増やそうとしていますが、コンソールでエラーが発生し続けます - POST localhost/slots/game/lines404 (Not Found) 。ところで、私は Codeigniter を使用しています。

コードは次のとおりです。

PHP (コントローラー)

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Game extends CI_Controller {
    function __construct()
    {
        parent::__construct();
    }
    function index(){
    }
    function win()
    {
        $this->session->set_userdata( array('win') => $win);
        $win = $this->input->post('win');
    }
    function lines()
    {
        $this->session->set_userdata( array('lines') => $lines);
        $lines = $this->input->post('lines');
        echo $lines++;
    }
    function wager(){
        $this->session->set_userdata( array('wager') => $wager);
        $wager = $this->input->post('wager');
    }   
}
?> 

そして、これが私のAjaxです-

function lines()
{
var lines = parseInt($('#lines span').html()) + 1;
$.ajax({
        type: 'POST',
        url: base_url + 'game/lines',
        data: { lines: lines },
        success:function(response){
            if(response <= 8){
                $('#lines span').html(response);
                return true;
            }
            else return false;
        }

});
}

そして、私のHTMLで私は呼び出しますlines function onclick.私は仮想ホストとして最新のxamppを使用しています.CIには1つのカスタムルートもあります-

$route['game/(:any)'] = "game/$1";
PS base_url は JS で変数として定義されています。

4

6 に答える 6

1

コメントでわかったように、あなたの問題は url_rewrite です。これを試して:

.htaccess というファイルを作成し、index.php ファイルがあるルート フォルダーに配置します (先頭のドットに注意してください)。次のコードを記述します。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

application/config/config.php では、インデックス ファイル オプションは次のように空にする必要があります。

$config['index_page'] = '';
于 2013-05-04T12:40:34.887 に答える
0

ルートを変更してみてください:

$route['game/(:any)'] = "game/lines/$1";

refer to the codeigniter user_guide to learn more about URI routing.

ところで、あなたは .htacess を使っていますか?

于 2013-05-04T14:52:25.207 に答える