0
我想從視圖發送數據到控制器使用AJAX,但我的代碼不起作用。我的代碼有什麼問題?當我點擊按鈕並打開...我剛剛看到一個白色的屏幕。ajax post geolocation not woking
我嘗試這樣做:
<button onclick="postLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function postLocation() {
var lat = [ + position.coords.latitude +];
var long =[ + position.coords.longitude];
$.ajax({
url: 'dosen/lokasi',
type: "post",
data: {lat:lat, long:long},
success: function(response){ // What to do if we succeed
if(data == "success")
alert(response);
},
error: function(response){
alert('Error'+response);
}
});
}
}
</script>
控制器的方法:
$latuser = Input::File('lat');
$longuser = Input::File('long');
echo $latuser;
和路線:
Route::get('/dosen/lokasi', '[email protected]');
Route::post('/dosen/lokasi', '[email protected]');
if(data ==「success」)//這個數據變量來自哪裏? –