Simple Ajax/Codeigniter request

前端 未结 8 782
無奈伤痛
無奈伤痛 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 15:48

    use site_url() of codeigniter

     function increase(){
       var number = parseInt($('#number').html()) + 1;  
       $.ajax({
         type: 'POST',
         url: '',
         data: { increse:number }, //<--- here should be increase
         success:function(response){
            $('#number').html(response);
         }
      });
    

    }

    however, adding http:// in front of localhost should work

     url: 'http://localhost/test/welcome/increase',
    

    but it is always better and recommended to use site_url() if you are calling a controller in CI...so that this won't give you errors while when you upload it to live server.

提交回复
热议问题