我正在使用laravel 5.1,我正在尝试将一些值保存到数据库中。
我正在使用javascript,从该脚本我获取Geo-location,我试图存储在数据库中的值。但是,当我提交数据来存储获取的值时,我得到错误:
VerifyCsrfToken.php第53行中的TokenMismatchException:
同样在控制台中我收到错误:
POST http://localhost:8888/address/218/3 500(内部服务器错误)
这是我的javascript代码:
<script>
window.onload = function() {
var latlng = new google.maps.LatLng(18.530201709586557, 73.86972429298089);
var map = new google.maps.Map(document.getElementById('map'), {
center: latlng,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: 'Set lat/lon values for this property',
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function(a) {
console.log(a);
var div = document.createElement('div');
div.innerHTML = a.latLng.lat() + ', ' + a.latLng.lng();
//document.getElementsByTagName('body')[0].appendChild(div);
var latitude = a.latLng.lat();
var longitude = a.latLng.lng();
console.log(latitude, longitude);
getcity(latitude, longitude);
});
};
function getcity(latitude, longitude){
var geocoder;
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(latitude, longitude);
geocoder.geocode(
{'latLng': latlng},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
var add= results[0].formatted_address ;
var value=add.split(",");
count=value.length;
country=value[count-1];
state=value[count-2];
city=value[count-3];
var address = value.join([separator = ',']);
console.log(address);
console.log("city name is: " + city);
console.log("state name is: " + state);
console.log("country name is: " + country);
var location = "<b>Address</b>: " + address + "<br/><br/>";
location += "<b>Latitude</b>: " + latitude + "<br/>";
location += "<b>Longitude</b>: " + longitude + "<br/><br/>";
location += "<b>City</b>: " + city + "<br/>";
location += "<b>State</b>: " + state + "<br/>";
location += "<b>Country</b>: " + country + "<br/>";
document.getElementById('addresss').innerHTML = location;
var event_id = document.getElementById('eventid').value;
var pro_id = document.getElementById('provider_org_id').value;
console.log("event id is: " + event_id);
console.log("provider id is: " + pro_id);
var data_to_send = {
address: address,
latitude: latitude ,
longitude: longitude ,
city: city ,
state: state ,
country: country ,
eventid: event_id,
providerid: pro_id,
};
var str = "http://localhost:8888/address/"+event_id+"/"+pro_id;
$.post(str , data_to_send).done(function(data){
console.log(data);
});
}
else {
console.log("address not found");
}
}
else {
console.log("Geocoder failed due to: " + status);
}
}
);
var p1 = new google.maps.LatLng(18.530201709586557, 73.86972429298089);
var p2 = new google.maps.LatLng(latitude, longitude);
console.log("Straight Line Distance From Le Meridien " + calcDistance(p1, p2) + " Km");
//calculates distance between two points in km's
function calcDistance(p1, p2){
return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);
}
}
任何人都可以告诉我为什么我会收到这些错误&amp;如何解决它们?
修改
控制器:
public function EventVenue(Request $request,$pro_id,$event_id)
{
$input = $request->all();
$input['event_id'] = $event_id;
$input['pro_id'] = $pro_id;
EventVenue::create($input);
return view('event.pic_upload',compact('event_id','pro_id'));
//return "Event Venue";
}
型号:
class EventVenue extends Model
{
protected $primaryKey = 'id';
protected $table = 'event_venue';
protected $fillable = [
'event_id',
'manual_address',
'google_address',
'city',
'state',
'country',
'latitude',
'longitude',
];
}
答案 0 :(得分:0)
在你的项目文件夹中,转到app / Kernel.php并评论$ middleware&#39; App \ Http \ Middleware \ VerifyCsrfToken&#39;。多数民众赞成