这是否可以在不加载数据的情况下将数据发送到视图?我正在为 codeigniter 开发谷歌地图库。我有在列表页面上列出酒店的场景,当用户单击地图时,它会加载显示该地址的谷歌地图。我正在使用 ajax 调用控制器中的函数。问题是输出有两种类型的数据。一个应该插入head
到页面中,另一个应该插入到body
特定的页面中div.
echo $map['html'];
echo $map['js'];
html
应该div
在 head 中插入 while 'js'。两者都是函数的输出并返回以响应 Ajax。
ajax 调用的view
文件已经被另一个函数加载。如何处理?
查看文件(Ajax 函数)
function showMap(id)
{
var detail_id = id.replace('map_','detail_desc_');
var hotel_id = id.replace('map_','');
$("#detail_map_"+hotel_id).html('loading');
$("#"+detail_id).slideDown('fast');
var data = hotel_id;
$.ajax({
url:'<?php echo base_url() . "hotels/getMap";?>',
data:'id='+data,
type:'get',
cache: false,
success: function(data) {
alert(data);
//$("#detail_map_"+hotel_id).html(data);
}//end success
});//end ajax
}
控制器功能
public function getMap()
{
$id = $_GET['id'];
$map_config['directions'] = true;
$map_config['center'] = 'G 11 Markaz, Islamabad Pakistan';
// Initialize our map. Here you can also pass in additional parameters for customising the map (see below)
$this->googlemaps->initialize($map_config);
// Set the marker parameters as an empty array. Especially important if we are using multiple markers
$marker = array();
// Specify an address or lat/long for where the marker should appear.
$marker['position'] = 'G 11 Markaz, Islamabad Pakistan';
$this->googlemaps->add_marker($marker);
// placed where we want the map to appear.
$data['map'] = $this->googlemaps->create_map();
//print_r($data['map']);
echo $data['map']['html'];
echo $data['map']['js'];
//these two echos are sent back in response to ajax function
}
现在我想把标签放在里面,而另一个echo $data['map']['js'];
放在里面。head
body
div