How to get data from database using AJAX in CodeIgniter?

后端 未结 1 861
忘了有多久
忘了有多久 2020-12-11 11:58

I wonder how to get data from database using AJAX in CodeIgniter. Could you please check the code below to find out the reason of problem? Nothing happens when I click on th

相关标签:
1条回答
  • 2020-12-11 12:28

    Try this:

    $(function(){ // start of doc ready.
       $(".faq_title").click(function(e){
          e.preventDefault();  // stops the jump when an anchor clicked.
          var title = $(this).text(); // anchors do have text not values.
    
          $.ajax({
            url: 'faq/get_faq_data',
            data: {'title': title}, // change this to send js object
            type: "post",
            success: function(data){
               //document.write(data); just do not use document.write
               console.log(data);
            }
          });
       });
    }); // end of doc ready
    

    The issue as i see is this var title = $(this).val(); as your selector $(".faq_title") is an anchor and anchors have text not values. So i suggested you to use .text() instead of .val().

    0 讨论(0)
提交回复
热议问题