I'm trying to apply a "Like" button to my website. I am using Codigniter, Ajax and Jquery when clicked as a button, then the data should be entered in the database and if the button is pressed unlike the button, then it should be removed from the database. But I'm facing a problem in the model, when I click the button, the data is not added to the database. Please help me find a solution.
This is my jazzary file "likeitem.js"
function egim (postId) {if ($ ("# likeItem _" + PostId) .text () = = "Likes") {$ ("# likeItem _" + postId) .html ('Contrast'); Var objective = "likes"; } And {$ ("# likeItem _" + postId) .html ('like'); Var objective = "unlich"; } $ .jax ({type: "post", url: "http: //localhost/codeigs_marty/index.php/user/likeItem", data: "post id =" + post id + "purpose =" + purpose, success: Function () {}}); return false; }
This is my model "usermodel.php"
Like the public function item () {$ Id = $ this- & gt; Session-> User data ('userID'); $ PostId = $ this- & gt; Input-> Post ('postId'); $ Objective = $ this- & gt; Input-> Post ('objective'); If ($ objective == "likes") {// 'echo' test '; // Go out(); $ Data = array ("userID" = & gt; $ id, "postTextID" => $ postId,); $ This- & gt; Db- & gt; Insert ('like', $ data); } Else {echo 'is'; }}
This is my view file "home.tpl"
lift; Li & gt; & Lt a class = "as-the-opposite" href = "#" id = "items such as {{item} ['postID']}" onclick = "such as ({$ item ['postID']})" & gt; Like & lt; / A & gt; ; & Lt; / Li & gt; This is my admin "user.php"
public function egite () {$ this -> usermodel-> itemLike (); }
you make a mistake here Are you & amp;
I forgot to enter the symbol. Try this code
Data: "PostID =" + PostID + "and purpose =" + objective,
Full code: If you want to tamper with results Ajax, you can do something in the form of the following code on the success block:
$ .ajax ({type: "POST", url: "Http: //localhost/codeigs_marty/index.php/user/ LikeItem", data: "postId =" + postId + "and purpose =" + purpose, success: function (data) // console.log (data) -> date to see Return or not}});
No comments:
Post a Comment