用户提交表单后,将显示结果的新视图。结果视图将使用表单字段来创建JSON对象,将带有ajax请求的JSON发送到服务器并接收包含所有结果的JSON响应。然后使用视图呈现结果。这一切都很好但是当刷新结果页面时,所有结果都消失了。我如何制作它以便在刷新页面后我的结果会继续显示?我现在要做的是更改URL以使其包含查询,然后结果视图将使用URL形成请求并将其发送到服务器。这是我在这里尝试实现的建议行动方案吗?感谢。
答案 0 :(得分:0)
您需要在页面加载时调用调用ajax请求的函数。当用户再次加载页面时,您的值将丢失,因为它将重置为默认window.onload = function() {
// put something here so the function will not call if the ajax call has not been called beforee
yourFunction(param1, param2);
};
等。
如果你想让onload方法获取参数,你可以做类似的事情:
@foreach($shoppingCarts as $items)
<tr>
<td class="name"><a href="#">{{ $items->product_name }}</a></td>
<td class="price">{{ $items->product_price }}</td>
<td class="total"> <a href="#"><img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></a></td>
</tr>
@endforeach
这个onload会为你调用这个函数,无论每次运行ajax调用是什么。
当然你需要验证,所以如果之前没有使用过ajax请求,它就不会调用该函数。查询字符串成功等等时的内容。