php - Not getting an AJAX response -


i'm new ajax found tutorial , hacked fit php code. it's "like" button tutorial , inside of code works okay adding "like" count total database.

the problem once click "like", number of likes doesn't update (on page).

the original tutorial code works fine, did stupid.

here's code index.php

function cwrating(id,type,target){ $.ajax({     type:'post',     url:'rating.php',     data:'bt_id='+id+'&type='+type,     success:function(msg){         if(msg == 'err'){             alert('some problem occured, please try again.');         }else{             $('#'+target).html(msg);         }     } }); } 

and spot shows , count:

<span class="like" onclick="cwrating(<?php echo $row_bt['bt_id']; ?>,1,'like_count<?php echo $row_bt['bt_id']; ?>')"></span>  <span class="counter" id="like_count<?php echo $row_bt['bt_id']; ?>"><?php echo $row_bt['like_num']; ?></span> 

this entire rating.php page:

include_once("likes.php"); $likes = new likes(); if($_post['bt_id']){ //previous tutorial data $prev_record = $likes->get_rows($_post['bt_id']); //previous total likes $prev_like = $prev_record['like_num'];  //calculates numbers of or dislike if($_post['type'] == 1){     $like = ($prev_like + 1);     $return_count = $like; }else{     $like = $prev_like; }  //store update data $data = array('like_num'=>$like,'like_date'=>date("y-m-d h:i:s")); //update condition $condition = array('bt_id'=>$_post['bt_id']); //update tutorial dislike $update = $likes->update($data,$condition);  //return or dislike number if update successful, otherwise return error echo $update?$return_count:'err'; } 

i want have response in .counter class, i'm assuming it's ajax code needs tweaking.

probably have error in php code, use google chrome see this.

1. right click on page , select inspect element; 2. click on "network" tab; 3. find , click on ajax request in "name path" column (rating.php); 4. go "response" tab; 5. see response of ajax request. 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo