1

My current URL is http://localhost/create-story/galleries/wedding Want to Make URL is http://localhost/create-story/galleries/wedding?query=VALUE_FROM_AJAX_RECIEVER

My Ajax function is

function liveSearch(val) {
    $.ajax({
        url: "{{ route('search_wedding') }}",
        method: 'GET',
        data: {query: val},
        dataType: 'json',
        success: function (data) {
            $('#gallery').html(data);
        }
    })
}

$('#btn-bridal').on('click', function () {
    liveSearch($(this).text());
});

Is It possible to change URL from AJAX after success? want to add request value In Url. Thanks

4
  • usefulangle.com/post/81/javascript-change-url-parameters Commented May 21, 2020 at 11:44
  • You need to redirect using location.href Commented May 21, 2020 at 11:44
  • Hi GaloisGirl, I make the url from your link. How can I set now? any way? Commented May 21, 2020 at 11:56
  • Hi Ehsan, How to redirect location.href without loading? Commented May 21, 2020 at 11:57

1 Answer 1

1

I think this will do the trick for you:

function liveSearch(val) {
    let url =  "{{ route('search_wedding') }}?query=" + val;
    window.location = url;
}

$('#btn-bridal').on('click', function () {
    liveSearch($(this).text());
});

If it doesn't work please comment it and I will delete the answer if it's not bringing any result.

Sign up to request clarification or add additional context in comments.

7 Comments

It's nice to share the solution and give back to community... can you describe how did you solve it?
when I use AJAX. I faced problems with pagination. Then I Used get method with request variable and redirect to new route. That's my solution. Ajax didn;t work for me. Because I can't use pagination when I use AJAX.
So did you use something like I've written in my answer or something completely different?
Yes. completely Different.
I fully removed ajax from project.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.