显示ajax请求的编码器
Codeigniter displaying ajax request
我是一个Codeigniter新手。我花了很长时间来解决这个问题。我在view。php中有一个textview。按下按钮,我想把文本发送到服务器(php文件),处理它,并在页面上显示结果。我现在的代码是:
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..');
}
});
}
用户控件
<?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>";
}
}
和我的textview
<textarea rows="3" cols="25" id="post_text" >Some random text</textarea>
<input type="submit" id="post_bttn" value="Post" onclick="verify()">
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..');
}
});
}
现在您没有向Ajax请求传递任何参数。您的数据将是
data: {post_text:$('#post_text').text()},
在控制器文件中使用下面的strip_tags()
$output = strip_tags($text,'<br><br/>');
相关文章:
- 地理编码器 - IE8 中的编码问题
- 谷歌地图API地理编码器,受边界限制
- 将地理编码器的位置保存到数组中
- 在一个模式AjAX编码器中显示不同的Gallery
- 当点击一个标记时,地理编码器返回先前存储的值
- 谷歌地理编码器找到佐治亚州,而不是国家
- 如何防止谷歌地理编码器从其他国家/地区返回结果
- 防止在地理编码器谷歌地图API中循环
- 地理编码器仅适用于chrome,不适用于Firefox / IE / android
- 净化编码器中的输出
- 谷歌地理编码器返回错误的地址坐标
- 列出使用 Google 地图地理编码器 API 获取的一组地址
- 编码器点火器未验证输入文本
- 地理编码器 API 仅返回街道地址
- 如何在编码器中使用具有相同名称的多个输入插入数据
- 谷歌地图地理编码器,计算距离,
- Windows媒体编码器9插入(链接,脚本)处理
- Ajax请求没有使用编码器的响应
- 显示ajax请求的编码器
- 谷歌地理编码器从请求值返回不同的纬度和经度