将我的AJAX从GET方法更改为POST方法后, 每次运行JavaScript时,我都会收到此内部服务器错误500。 我真的找不到任何错误。
我在窗户上使用laravel 4.2。
keyup上的JavaScript函数:
function usernameCheck()
{
var input = document.getElementById("usernameInput");
var icon = document.getElementById("userIcon");
var xmlhttp,
username = document.getElementById("usernameInput"),
message = document.getElementById("usernameMessage");
if(username.value != "")
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
message.innerText = "";
icon.style.color = xmlhttp.responseText;
input.style.border = xmlhttp.responseText+" solid 2px";
if(username.value.length < 4)
{
message.innerText = "username is too short";
message.style.color = "red";
}
else if(xmlhttp.responseText == "false")
{
message.innerText = "username is already in use";
message.style.color = "red";
}
else if(xmlhttp.responseText == "true")
{
message.innerText = "username is available";
message.style.color = "green";
}
}
}
xmlhttp.open("POST", "usernamevalidation", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form- urlencoded");
xmlhttp.send("username="+ username.value);
}
else
{
icon.style.color = "";
input.style.border = "";
message.innerText = "";
}
}
Route.php:
Route::post('usernamevalidation', 'UserController@validateUsername');