좌표 값을보기에서 컨트롤러로 전송하려고합니다. add
google api에서 가져온 좌표이지만 문제가 있습니다.이 스크립트는 내가보기에서 사용하고 있습니다. _add
. 자바 스크립트 콘솔은 좌표를 잘 출력하기 때문에 스크립트가 작동합니다.게시 방법을 통해보기에서 컨트롤러로 좌표를 전달합니다.
<script type="text/javascript">
$(document).ready(function(){
get_location();
});
function get_location()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.post('http://firstaid:8888/add', { latitude:latitude, longitude:longitude });
});
}
}
</script>
이제이 뷰에서 컨트롤러로 값을 전달하여 PHP codeigniter 컨트롤러에서 변수로 사용할 수 있습니다. 이렇게하려면 $this->input->post
을 사용합니다. 실수는 내가 $latitude
을 인쇄 할 때
function index()
{
$data['title'] = 'Add';
$latitude = $this->input->post('latitude');
$this->load->view('templates/_header', $data);
$this->load->view('_add');
}
하지만, 변수가 될 수 blank.where입니다? 아마 내가보기를로드하기 전에 게시물을 호출하기 때문에?
데이터를 컨트롤러로 전달하는 또 다른 방법이 있습니까? 이것에
$.post('http://firstaid:8888/add', { latitude:latitude, longitude:longitude });
:
는 불행히도 결과 ... 나는 ($ 위도) 인 print_r을 시도하지; 주사위(); 하지만 결과가 없습니다 ... –
PHP'$ _POST' 배열을 직접 검사 해 보셨습니까? –
print_r ($ _ POST ('latitude'))을 시도했습니다. 하지만 난이 오류가 나타납니다 : 치명적인 오류 : 함수 이름은 문자열이어야합니다 몇 가지 아이디어? –