donglu1971 2016-03-14 09:36
浏览 24
已采纳

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

I am using laravel 5.1, I am trying to save some values to database.

I am using javascript, from that script i fetch Geo-location, that value i am trying to store in database. But, when i submit data to store that fetched value i got error as:

TokenMismatchException in VerifyCsrfToken.php line 53:

Also in console I get error as:

POST http://localhost:8888/address/218/3 500 (Internal Server Error)

Here is my javascript code:

<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);
    }
}

Can any one tell me why am i getting those errors & how to solve them?

EDIT:

Controller:

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";
}

Model:

    class EventVenue extends Model
{
    protected $primaryKey = 'id';
    protected $table = 'event_venue';

    protected $fillable = [
        'event_id',
        'manual_address',
        'google_address',
        'city',
        'state',
        'country',
        'latitude',
        'longitude',
    ];
}
  • 写回答

1条回答 默认 最新

  • 普通网友 2016-03-14 09:39
    关注

    In your project folder go to the app/Kernel.php and comment $middleware 'App\Http\Middleware\VerifyCsrfToken'. Thats it

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器