我在视图中有这段代码
@if($order->accept == 1)
<script>
window.setTimeout(function () {
window.location.href = "http://localhost:8000/confirmed/{{$order->id}}";
}, 12000);
</script>
@endif
和控制器
public function confirmed($order_id)
{
$order = Order::find($order_id);
if ($order->accept == 4) {
$message = '';
return view('trip.html.trip', compact('order', 'message'));
} else {
return view('trip.html.trip', compact('order'));
}
}
我想在没有刷新页面的情况下检查我的订单接受情况 通过这种方式我可以刷新,但我不想要它。有人能帮助我吗?
答案 0 :(得分:0)
以下将帮助您了解ajax并渲染
one
two
'three four three and a half'
five
https://jsfiddle.net/uqw0L2r4/18/
我已经使用 ajax 点击按钮加载了小提琴登录页面,你必须在url中添加你的laravel URL并将成功(数据)附加到你的容器。
编辑 - 根据您的超时功能
<h1>helllo</h1>
<button onclick="getGoogle();">Get request</button>
<div id="google">
</div>
<script type="text/javascript">
function getGoogle(){
$.ajax({
url:"https://jsfiddle.net/user/login/",
type:'get',
success: function(data){
console.log(data);
document.getElementById('google').innerHTML = data;
}
});
}
</script>
希望这对你有帮助。
答案 1 :(得分:0)
您正在寻找的是AJAX。它代表异步JavaScript和XML。它允许您在不刷新网页的情况下预先形成请求。
以下是关于Get和Post AJAX请求方法的W3Schools页面。 (GET是一种不安全查询的方法,POST是一种将表单数据发送到控制器的安全方法)
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
以下是单击按钮时触发的AJAX GET请求的W3Schools示例。
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
GET和POST之间的区别。
答案 2 :(得分:0)
我通常会尽量避免使用AJAX,因为我不太喜欢它,我应该说些要求。
您要执行的操作会刷新页面上的元素,但不会刷新页面。当然可以!
根据服务器如何服务(答复)您的请求来定义您可以做什么。我将使用MkNxGn Proquest根据您上面的内容来构造答案。
MkNxGn.pro提供了一种通过MkNxGn Proquest发出XML HTTP请求的简洁方法。
将此内容添加到您的页面<script src="https://mknxgn.pro/scripts/Proquest_Proquest-v1.0.js"></script>
这是你的要求。 Proquest("POST",
URL_HERE,
DATA,<br>
HEADERS,
RType,
Ignore JSON errors,
Callback);
window.setTimeout(function () { Proquest("GET", "http://localhost:8000/confirmed/" + OrderID, Skip, Skip, 'request', false, function(resp) {
\*Resp = the request object so you can parse through it
The request is made, with no further guidance on what your trying to do
I'm guessing as to what to do at this point*\
document.getElementById('ThingToUpdate').innerHTML = resp.responseText
})}, 12000);
将替换
window.setTimeout(function () {
window.location.href = "http://localhost:8000/confirmed/{{$order->id}}";
}, 12000);
您可以在MkNxGn Proquest
上查看Proquest的文档编辑是要包含保持刷新的时间间隔。