【发布时间】:2013-11-27 06:06:54
【问题描述】:
我需要帮助!我想从 Codeigniter 服务器检索 json 数据。 这是我的 html 本地文件 (d://myproject/index.html)
$.ajax({
type: "POST",
url : serverUrl+'mobcontroller/users/',
crossDomain: true,
async: false,
data : $("#formlogin").serialize(),
dataType : MobileJsonType[1],
beforeSend : function(){//do stuff here},
success : function(responseData) {
alert(JSON.stringify(responseData));
},
error : function(jqXHR, textStatus, errorThrown) {
// do stuff here
},
complete: function(xhr, settings){
alert(JSON.stringify(xhr)+'\n'+settings);
}
});
codeigniter 控制器看起来像这样
public function index()
{
$type_message = 'success';
$message = 'Mobile plateform';
$this->output->set_header("Access-Control-Allow-Origin: *");
$this->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
$this->output->set_status_header(200);
$this->output->set_content_type('application/json');
$this->output->_display();
echo json_encode( array('type_message' => $type_message, 'message' => $message) );
}
我获得了带有js错误的json数据响应
Uncaught SyntaxError: Unexpected token :
请帮帮我!
【问题讨论】:
-
试试这个,成功:function(responseData) { alert(responseData.type_message);}。假定 MobileJsonType[1] 值为
json
标签: html json codeigniter