我的JavaScript以下和平:JSON字符串,但PHP变量打印空
$('.showEditForm').click(function() {
var webpagefileID = this.id;
if($('#editForm').css('display', 'none')) {
$('#editForm').css('display','block');
$('#allFilesTable').css('display','none');
}
$.post
('http://localhost/myproject/Controllername/display_edit_record_form', { webpagefileID: webpagefileID }, function(result) {
});
});
使用后,我打电话方法display_edit_record_form我笨控制器
这里是在我笨控制器命名display_edit_record_form方法的代码:
public function display_edit_record_form($webpagefileID)
{
$webpagefileID = $this->input->post('webpagefileID');
$data['webpagefile'] = $this->Webpage_file_model->get($webpagefileID);
//$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data['webpagefile']));
echo json_encode(array("message" => $data['webpagefile']));
}
在PHP的看法,我想显示与下面的代码数据:
var_dump($message);
echo "<br />";
$myarr1 = json_decode($message);
print_r($myarr1);
echo "<br />";
$myarr2 = json_decode($data['webpagefile']);
print_r($myarr2);
echo "<br />";
$myarr3 = json_decode($webpagefile);
print_r($myarr3);
我也得到一个NULL和2个空数组 在控制台不过,我可以看到这一点:
现在,在控制台,打开编辑表单的时候,我可以看到JSON字符串
{"message":
{"webpagefileID":"10",
"webpageID":"38",
"webpagefileName":"New file",
"webpagefileShowInRelatedFiles" :"1",
.......continues.....
我需要帮助,在视图中我的PHP代码来显示这个字符串,所以我可以populoate我的表单字段有....
有没有什么办法可以在视图中获得php数组的结果? – user2417624
不是我所知道的。如果你想在视图中使用php数组的结果,你必须调用你的控制器中的方法并将值传递给视图。但在这种情况下,这不会是异步的权利? –
是的,这不是我想要的。 – user2417624