stop reloading a page from javascript function in laravel

Viewed 96

i have view page where i am trying to update the sortorder column everytime when user changes value in that particular column.so now the problem is when i update the value the page is refreshing..i would liek to stop that refreshing the page

Here is my scripting code:

function changeOrder(id, value)
{

    var url = '{{ route('subject.update_sort') }}';

    var dataset = {
        id: id,
        value: value,
    };

    axios.patch(url, dataset)
    .then(function(response) {
        Swal.fire({title: 'Updated!', text: response.data.message, type: 'success'})
        .then(function(){
            location.reload();
            return false;
        });
    })
    .catch(function(error) {
        console.log(error);
        Swal.fire({
            type: 'error',
            title: 'Oops...',
            text: 'Something went wrong! '+error.response.data.message
        })
    })
}
Can anyone help me how can i do that..i try removing `location.reload` but when i did that the page is not refreshing but the sort order column is not coming in asc order. if i keep that back page is refreshing and the sort order column is coming in asc order.
2 Answers

Well in your patch request you are reloading the page

.then(function(){
    location.reload();
    return false;
});

You need to remove location.reload();

If you don't want to reload the page and still show updated data then you'll have to call your render function(javascript function) with updated data.

Your html document won't update on its own, assuming you are not using a template engine and using javascript to append data to document, you would want to call that function again with updated data received from patch request, then your html document will show updated data.

Related