Answer the question
In order to leave comments, you need to log in
AJAX fetch() and POST?
Hello. Do not prompt in what there can be a problem. When using fetch () for some reason, the request is sent not to the desired page, but to the main one. Thanks
const urlSend = '/admin/users/filter222';
const typeSend = 'POST';
// Вот так все работает как нужно
const request = new XMLHttpRequest( );
request.open( typeSend, urlSend, true );
request.onload = event => console.log( event.currentTarget.responseText );
request.send( );
// здесь идет запрос и выдает весь HTML главной страницы в моем случае http://localhost:8084
fetch( urlSend, { method: typeSend } )
.then( response => response.text( ) )
.then( text => console.log( text ) );
// Так идет запрос на верный адрес, только на GET, а мне нужен POST
fetch( urlSend )
.then( response => response.text( ) )
.then( text => console.log( text ) );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question