Ajax request return success message but data does not insert into database

Shamim Forhad

I am sending a ajax request it also returning success message but data is not inserting. Basically it is a link, when I will will click on the link then ajax will send a request to controllers and in database it increase the value with the previous value by 1. I have tried pass huge times but failed. This is a codignator project. It will grateful if you kindly help.

Ajax File :

$(document).ready(function(){

	$("#like").click(function(e){
	    e.preventDefault(); // <------this will restrict the page refresh
        var post_id = $(this).prop('rel');
	    $.ajax({
	        url: "http://localhost/ci_website/index.php/site/add_like",
	        type: 'POST',
	        data : post_id,
            dataType: 'json',
	        success: function(res) {

	            if (res.success) {
	            	alert(res.msg);
                } else {
                    alert(res.msg);
                }
	        }

	    });

	    return false;
	});	

});
View File :

<a id="like" class="like_btn" rel="<?php echo $blog['blog_id'];?>" href="<?php echo site_url('site/add_like') . '/' . $blog['blog_id'];?>">Like</a>
Controller File :

 public function add_like()
{
     header('Content-Type: application/json');
    if ($this->input->is_ajax_request()) {
        $post_id = $this->uri->segment(3);

        $this->db->set('post_like', '`post_like` + 1', FALSE);
        $this->db->where('blog_id', $post_id);
        $add_post_view = $this->db->update('wb_blog');
        if ($add_post_view) {
            die(json_encode(array('success' => true, 'msg' => 'Your Like has been sent successfully.')));
        } else die(json_encode(array('success' => false, 'msg' => 'Something bad happened!!! Please, try again.')));
    }


}
Shamim Forhad
 url: "http://localhost/ci_website/index.php/site/add_like/"+post_id,

I have add 'post_id' after the link. This is work fine. I did not define the exact id against which the row of the table will be affected.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AJAX call return success message but post data never insert into db

From Dev

jQuery ajax return success data

From Dev

jQuery ajax return success data

From Dev

AJAX success request "message text" to be displayed back

From Dev

Data does not insert into database

From Java

jQuery: Return data after ajax call success

From Dev

How to return data from ajax success function?

From Dev

jQuery AJAX return the function as data upon success

From Dev

Success message is not showing in html page with ajax/jquery request

From Dev

JQuery/Ajax return Success message and display Saved indicator

From Dev

Ajax on Success message

From Dev

Ajax request return 200 OK but error instead of success

From Dev

undefined return ajax success

From Dev

'INSERT INTO' does not insert data to my sql database

From Dev

'INSERT INTO' does not insert data to my sql database

From Dev

SqlCommand INSERT query does not insert data into the database

From Dev

How to add $_SESSION variable into an Ajax Request and INSERT data into mysql database PHP?

From Dev

jQuery ajax request: how to access sent data in success function?

From Dev

Changing ajax POST data for a second request using .done() instead of success

From Dev

Add ajax success return json object data in html form

From Dev

Why does not insert these values in database using Ajax

From Dev

Insert data through ajax into mysql database

From Dev

Can't insert data into database using ajax

From Dev

AJAX doesn't insert data into database

From Dev

Find data attribute and insert it to database using ajax

From Dev

data insert twice in database , ajax post

From Dev

Unable to insert data into mysql database using AJAX

From Dev

PHP data in AJAX success?

From Dev

ajax request doen't return data

Related Related

  1. 1

    AJAX call return success message but post data never insert into db

  2. 2

    jQuery ajax return success data

  3. 3

    jQuery ajax return success data

  4. 4

    AJAX success request "message text" to be displayed back

  5. 5

    Data does not insert into database

  6. 6

    jQuery: Return data after ajax call success

  7. 7

    How to return data from ajax success function?

  8. 8

    jQuery AJAX return the function as data upon success

  9. 9

    Success message is not showing in html page with ajax/jquery request

  10. 10

    JQuery/Ajax return Success message and display Saved indicator

  11. 11

    Ajax on Success message

  12. 12

    Ajax request return 200 OK but error instead of success

  13. 13

    undefined return ajax success

  14. 14

    'INSERT INTO' does not insert data to my sql database

  15. 15

    'INSERT INTO' does not insert data to my sql database

  16. 16

    SqlCommand INSERT query does not insert data into the database

  17. 17

    How to add $_SESSION variable into an Ajax Request and INSERT data into mysql database PHP?

  18. 18

    jQuery ajax request: how to access sent data in success function?

  19. 19

    Changing ajax POST data for a second request using .done() instead of success

  20. 20

    Add ajax success return json object data in html form

  21. 21

    Why does not insert these values in database using Ajax

  22. 22

    Insert data through ajax into mysql database

  23. 23

    Can't insert data into database using ajax

  24. 24

    AJAX doesn't insert data into database

  25. 25

    Find data attribute and insert it to database using ajax

  26. 26

    data insert twice in database , ajax post

  27. 27

    Unable to insert data into mysql database using AJAX

  28. 28

    PHP data in AJAX success?

  29. 29

    ajax request doen't return data

HotTag

Archive