无法让ajax工作编码器
Cannot get ajax to work codeigniter
我有ajax代码
$.ajax({
url: '<?php echo base_url(); ?>deleteRowUsingApiKey/index', //This is the current doc
type: "POST",
//dataType:'json', // add json datatype to get json
data: {name: '145'},
success: function(data){
console.log(data);
alert(data);
}
});
在php控制器
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL);
ini_set('display_errors', 1);
class DeleteRowUsingApiKey extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
echo json_encode('test');
}
}
我想在javascript中获得值'test'。但是我不能让这个工作
我想下面的代码会对你有所帮助
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL);
ini_set('display_errors', 1);
class DeleteRowUsingApiKey extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
//get data from ajax
//if you send request with post
$name = $this->input->post('name');
//if you send request with get
$name = $this->input->get('name');
// create bject for returning data
$return = array();
$return['status'] = 'OK';
$return['msg'] = 'some_message';
$this->output->set_content_type('application/json')
->set_output(json_encode($return));
}
}
代码必须在服务器端
是否包含了jquery库?就像
<script type="text/javascript" src="<?php echo base_url('js/jquery-1.10.1.min.js'); ? >"></script>
相关文章:
- 地理编码器 - IE8 中的编码问题
- 谷歌地图API地理编码器,受边界限制
- 将地理编码器的位置保存到数组中
- 在一个模式AjAX编码器中显示不同的Gallery
- 当点击一个标记时,地理编码器返回先前存储的值
- 谷歌地理编码器找到佐治亚州,而不是国家
- 如何防止谷歌地理编码器从其他国家/地区返回结果
- 防止在地理编码器谷歌地图API中循环
- 地理编码器仅适用于chrome,不适用于Firefox / IE / android
- 难以理解的工作装饰器功能
- 净化编码器中的输出
- 谷歌地理编码器返回错误的地址坐标
- 列出使用 Google 地图地理编码器 API 获取的一组地址
- 编码器点火器未验证输入文本
- 地理编码器 API 仅返回街道地址
- 如何在编码器中使用具有相同名称的多个输入插入数据
- 谷歌地图地理编码器,计算距离,
- Ajax不能工作的编码器
- 无法让ajax工作编码器
- Gmaps.js地理编码器不工作