lundi 14 mars 2016

"TokenMismatchException in VerifyCsrfToken.php line 53:" in laravel 5.1

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire