Simple Ajax/Codeigniter request

前端 未结 8 786
無奈伤痛
無奈伤痛 2021-01-25 15:43

I\'m having some issues with ajax and codeigniter. I\'ve already posted another question (link to question) and I thought I solved it, but I did not so I`m asking someone to wri

8条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 16:07

    First You should define your site base_url in application/config file then use this base_url with your ajax page call from where your call goes. Suppose your base_url is http://localhost/test/

    function increase(){
       var number = parseInt($('#number').html()) + 1;
       $.post('welcome/increase',{number :number},function(response){
              $('#number').html(response);
       });    
    }
    

    then change your increase function in controller like this

    function increase(){
       $increase = $_POST['number'];
    echo increase++;
    

    }

提交回复
热议问题