私のajaxコードに問題があります。ajaxでクリック時にスパン内の数を増やそうとしていますが、コンソールでエラーが発生し続けます - POST localhost/slots/game/lines
404 (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 で変数として定義されています。