laravel 5.1中的“ VerifyCsrfToken.php 53行中的TokenMismatchException:”

Shweta

我正在使用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);
    }
}

谁能告诉我为什么会出现这些错误以及如何解决这些错误?

编辑:

控制器:

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',
    ];
}
Prashant Rajput

在您的项目文件夹中,转到app / Kernel.php并注释$ middleware'App \ Http \ Middleware \ VerifyCsrfToken'。就是这样

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

VerifyCsrfToken.php第53行中的TokenMismatchException:在Laravel 5.1中

Laravel 5.1中VerifyCsrfToken.php第53行中的TokenMismatchException

Laravel 5,Forms,VerifyCsrfToken.php第46行中的TokenMismatchException

VerifyCsrfToken.php Laravel 5.2中的TokenMismatchException

VerifyCsrfToken.php 67行中的Laravel 5.2 TokenMismatchException

VerifyCsrfToken.php 67行中的TokenMismatchException

VerifyCsrfToken.php 67行中的TokenMismatchException:将paytm与laravel 5.3集成时

使用Ajax在Laravel上的VerifyCsrfToken.php 67行中的TokenMismatchException

如何在VerifyCsrfToken.php第46行中修复TokenMismatchException:使用Ajax和laravel 5.0?

VerifyCsrfToken.php 67行中的Laravel 5.2 ajax上传进度栏和TokenMismatchException

laravel模式提交表单获取错误“ VerifyCsrfToken.php第68行中的TokenMismatchException:”

VerifyCsrfToken中的TokenMismatchException-Laravel 5.1

上线后,VerifyCsrfToken.php 67行中的TokenMismatchException

通过edittable提交时,VerifyCsrfToken.php中的TokenMismatchException

Laravel TokenMismatchException VerifyCsrfToken.php:67查找路线

在Laravel 5中,如何为特定路由禁用VerifycsrfToken中间件?

Laravel 5:在VerifyCsrfToken外部验证令牌

Laravel 5 TokenMismatchException仅在iFrame中

Laravel 5中的PHP Soapclient

Laravel Dingo API和Middleware \\ VerifyCsrfToken.php的问题

Controller.php第268行中的1/1 NotFoundHttpException:找不到控制器方法。在laravel 5中

Laravel 5:Model.php中的MassAssignmentException

在Laravel 5中运行普通的PHP脚本

LengthAwarePaginator.php中的Laravel 5 ErrorException

PHP 5.6.9上的Laravel 5 TokenMismatchException

Laravel 5在RouteCollection.php第219行中的MethodNotAllowedHttpException:

RouteCollection.php第201行中的Laravel 5 MethodNotAllowedHttpException:

Laravel 5-RouteCollection.php第143行中的NotFoundHttpException

MainController.php 中的 PHP / LARAVEL 5 ErrorException