R
R
Ruslan Safronov2018-10-18 15:39:27
AJAX
Ruslan Safronov, 2018-10-18 15:39:27

Redirect in ajax response?

How to redirect to a page from ajax response? The problem is that Ajax simply sends in response the page to which the redirect should be made, and does not make the transition itself.
I suspect you need to do something like

var address = ... // адрес полученный ajax-запросом
document.location.href = address;

But how to get this same address received by ajax request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ihor Bratukh, 2018-10-18
@BRAGA96

More or less like this:

$.ajax({
  url: 'https://jsonplaceholder.typicode.com/posts',
  method: 'GET',
  dataType: 'json',
  success: function(posts) {
    window.location.href = posts[0].title;
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question