I'm a Codeigniter noob. I've been trying for quite some time now to solve this. I have a textview in my view.php. On button press, I want to send the text to server (php file) , process it and display result on page. My current code is:
javascript in view:
function verify(){
var posttext = $('#post_text').text();
$.ajax({
type: "post",
url: "http://localhost/naloga1/CodeIgniter/index.php/usercontroller/checkinput",
cache: false,
data: {post_text : posttext },
success: function(json){
try{
var obj = jQuery.parseJSON(json);
alert( obj['STATUS']);
}catch(e) {
alert('Exception while request..');
}
},
error: function(){
alert('Error while request..');
}
});
}
usercontroller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class UserController extends CI_Controller {
public function checkinput(){
$status = array("STATUS"=>"false");
$text = $_POST['post_text'];
if ($text != null){
$status = array("STATUS"=>"true");
}
echo json_encode ($status) ;
$output = $text.strip_tags();
echo "<p>".$output."</p>";
}
}
and my textview
<textarea rows="3" cols="25" id="post_text" >Some random text</textarea>
<input type="submit" id="post_bttn" value="Post" onclick="verify()">
Any help would be greatly appreciated.