JQuery Ajax POST in Codeigniter -
i have searched lot of tutorials post methods , saw answered questions here post still doesn't work...i thought should post here if guys see don't!
my js - messages.js:
$(document).ready(function(){ $("#send").click(function() { $.ajax({ type: "post", url: base_url + "chat/post_action", data: {textbox: $("#textbox").val()}, datatype: "text", cache:false, success: function(data){ alert(data); //as debugging message. } return false; }); });
my view - chat.php:
<?php $this->load->js(base_url().'themes/chat/js/messages.js');?> //i use mainframe framework loading script way valid <form method="post"> <input id="textbox" type="text" name="textbox"> <input id="send" type="submit" name="send" value="send"> </form>
last my controller - chat.php
//more functions here function post_action() { if($_post['textbox'] == "") { $message = "you can't send empty text"; } else { $message = $_post['textbox']; } echo $message; }
$(document).ready(function(){ $("#send").click(function() { $.ajax({ type: "post", url: base_url + "chat/post_action", data: {textbox: $("#textbox").val()}, datatype: "text", cache:false, success: function(data){ alert(data); //as debugging message. } });// have missed bracket return false; }); });
Comments
Post a Comment