Reputation: 296
On button click. I want page to redirect to a laravel route url using a separate script.
Below is my code:
<button id="myButton">Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "{{ route('customer.wishlist.remove',$item->id) }}";
};
onclick it directly showing the route link in the browser tab.
Please help me where iam going wrong. thank you.
Upvotes: 1
Views: 3190
Reputation: 6005
pass CSRF token and write window.location.href in your code
<button id="myButton">Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
window.location.href = "{{ route('customer.wishlist.remove',$item->id) }}";
};
or
<a href="{{ url('/path/' . $item->id . '/path(edit like)') }}" class="btn btn-xs btn-info pull-right">BUttonn naame</a>
Upvotes: 1
Reputation: 318
Try this
<button id="myButton">Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
window.location.href = "{{ route('customer.wishlist.remove',$item->id) }}";
};
Upvotes: 1