简体   繁体   中英

xhttp.send() get error POST 500 (Internal Server Error)

when trying to send the data to the server the error POST 500(internal server Error ) display here is my form

<form class="input-group" id="f">
    <div class="form" style="display :-webkit-inline-box;">
        <input type="text" class="form-control" name="comment" placeholder=" Comment ">
        <span class="input-group-btn">
                 {{--<input class="btn btn-default" type="button" onclick="loadDoc()" value="Comment!">!--}}

            <input class="btn btn-default" type="button" onclick="loadDoc()" value="Comment!">
             </span>
    </div>
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form><!-- /input-group -->

and this is the javascript code

    function loadDoc() {
        var dd = document.getElementById('f');
        var d = [];
        r=0;
        for (var i = 0; i < dd.elements.length; i++){
            if(dd[i].type == "text") {
            d[r] = dd[i].value;
            r++;
            }
    }
        var xhttp = new XMLHttpRequest();
        var url = "/place/{{$place->id}}";
        var params = "data="+d;
        xhttp.open("POST", url , true);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                var json = JSON.parse(this.response);
                console.log(json);
            }
        };
        xhttp.send(params);
    }

i am trying to make a comment

If you don't plan to use CSRF Token, than go to the

App/Http/Kernel.php

And delete or comment line

\App\Http\Middleware\VerifyCsrfToken::class

And your profilem is solved... otherwise add _token param in that xhttp request...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM