codeigniter - Jquery post with codeignitor -
I'm moving from WordPress to codeignitor but I'm struggling to call a controller function from a jquery post here. Here are my files
I have this in my home view
& lt; A class = "add_playlist" href = "5657584" & gt; & Lt; Img src = "http: // icon .iconarchive.com / icons / dryicons / simplistica / 32 / add-icon.png" alt = "playlist" /> & Lt; / A & gt; and in the footer
& lt; Script type = "text / javascript" src = "http://code.jquery.com/jquery-latest.js" & gt; & Lt; / Script & gt; & Lt; Script type = 'text / javascript' & gt; $ ('.add_playlist'). Live ('click', function () {warning ('add'); var video_url = $ (this) .attr ('href'); $ .post ("http: // localhost /code/index.php/home / Add_playlist ", {video_url: video_url}, function (response) {console.log (response);}); return back;}); So what I'm trying to do is send a function called add_playlist to my home controller. Here is the code in my home controller.
& lt ;? Php if (! Defined ('BASEPATH')) exit ('no direct script entry is allowed'); Class Home Expands CI_Controller {function add_playlist () {$ this- & gt; Load-> Model ('home_model'); // If HTTP Post is Sent, then add the data to the database ($ -> this-> Input-> Post ('video_url')) {$ video_url = $ this-> Input-> Post ('video_url'); $ This- & gt; Home_model-> Add ($ video_url); } Else {}}} return false; }); & Lt; / Script & gt; And here is my home model
So I want to do this adding a href to the database, someone can scan it and
thanks
this
add_playlistPOST http: //localhost/code/index.php/home/add_playlist500 (internal server error)
In your home controller's code, there is a duplicate javascript:
return false; }); & Lt; / Script & gt; ?
Should look like this:
& lt ;? Php if (! Defined ('BASEPATH')) Exit ('no permission to access any direct script'); Class Home Expands CI_Controller {function add_playlist () {$ this- & gt; Load-> Model ('home_model'); // If HTTP Post is Sent, then add the data to the database ($ -> this-> Input-> Post ('video_url')) {$ video_url = $ this-> Input-> Post ('video_url'); $ This- & gt; Home_model-> Add ($ video_url); } Else {}}}
Comments
Post a Comment