【发布时间】:2012-06-28 12:18:25
【问题描述】:
我正在使用 HMVC 代码点火器。我第一次尝试使用 jquery ajax。当我使用 POST 时,它会在使用 GET 时响应我的数据时给出未定义的错误。
$.ajax({
type: "POST",
url: filelink+"cart/add_cart_item",
data: {"product_id":id,"quantity":qty,"ajax":"1"},
dataType: "json",
success: function(msg){
alert( "Data Saved: " + msg );
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus + " " + errorThrown);
}
});
在谷歌搜索和 SO-ing 之后我到目前为止所尝试的 -
我的文件 url 位置可以直接访问。我检查了它。给予回应。
Firebug 为同一文件提供 500 个内部服务器错误。
使用 Get 对我的反应很好
在数据类型中添加了 json
控制器功能
class Cart extends CI_Controller { // Our Cart class extends the Controller class
function __construct()
{
parent::__construct();
$this->template->set('controller', $this);
}
function _remap()
{
$uri2 = $this->uri->segment(2);
if (is_numeric($uri2) OR $uri2 == FALSE) {
$this->index();
} else if ($uri2 == 'add_cart_item') {
$this->add_cart_item();
} else if ($uri2 == 'show_cart') {
$this->show_cart();
}
}
function add_cart_item(){
echo "asdfsadfdsf";
exit;
}
}
谁能帮帮我?
【问题讨论】:
-
你试过
var_dump($this->input->post('product_id'));吗?它有输出吗? -
@vikassharma:filelink 包含什么?
-
@vikassharma 你的 base_url() 是什么样的?您是否尝试过使用完全限定的 url?或者只是控制器的名称加上方法?
-
@vikassharma 如果您正常访问,您的控制器是否正常工作?我看到您实际上使用的是 hmvc,但您仍在扩展 ci_Controller 而不是 Mx_controller。
-
@Kyokasuigetsu 我对这个 codeigniter 和 hmvc 很陌生。实际上这是其他控制器的设计方式。其他页面使用 main.php 作为外部模板文件,并且内容通过加载部分显示在它们之间。可能是这引起了问题????他们都在使用 ci_controller。我复制了相同的 ....
标签: php jquery ajax codeigniter