【发布时间】:2015-09-10 13:22:23
【问题描述】:
我正在尝试做一个 ajax 验证,但我不知道为什么它不起作用。
这是我的 ajax 脚本:
<script type="text/javascript" language = "javascript">
function checkWords () {
var status = document.getElementById("status");
var u = document.getElementById("styled").value;
if(u != "")
{
status.innerHTML = 'Verifying...';
var hr = new XMLHttpRequest();
hr.open("POST","/topicnou",true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function(){
if (hr.readyState == 4 && hr.status == 200)
{status.innerHTML = hr.responseText;}
}
var v = "name="+u;
hr.send(v);
}
}
</script>
这是我的 php:
<?php
if(isset($_POST['name']) && $_POST['name'] != ""){
echo 'succes';
}
?>
PS:购买的脚本位于 TopicNou.blade.php 中,如果你去 localhost/topicnou 可以看到。
这是在我的控制台中显示的内容:
POST http://localhost/topicnou500(内部服务器错误)
XHR 完成加载:POST "http://localhost/topicnou"。
【问题讨论】:
-
嗯..不确定但您是否也发送了 CSRF 令牌?此外,如果您在 Mozilla 中查看 ajax 错误,您可能会获得更多见解。
-
@user3516962 我的页面上也有这个 如果你说的是这个
标签: javascript php ajax laravel