J
J
Jasulan982018-05-18 13:34:09
JavaScript
Jasulan98, 2018-05-18 13:34:09

Help,Make Post request(fetch)?

http://localhost:54316/Account/Register?role=Order...
in POSTMAN correctly adds to the database, but if the link is put in React Native, an error

fetch('http://localhost:54316/Account/Register',{
    method: "POST",
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    body:  JSON.stringify({
      role:"Заказчик",
      UserName:"Postks",
      PhoneNumber:"+16774521547",
      Password:"ssss",
      PasswordConfirm:"ssss*",
    }),
 })
 .then(function(response){ 
  return response.json();   
 })

▶[Unhandled promise rejection: TypeError: Network request failed]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
UNy, 2018-05-18
@UNy

function but(id) {

        fetch('/ajax', {method: 'POST',body:JSON.stringify({
                name:'vlad',
                id:id
            }),headers:{'content-type': 'application/json'}})
            .then(function (response) {
                alert(response.status); // 200

                return response.json();
            })
            .then(function (data) {
                alert(data.id);
                let elem = document.getElementById('h2o');
                elem.innerText = data.id;
            })
            .catch(alert);
    }

Here is my example of content change. In the first .then you return return response.json(); And where to? Make another then that takes this data and works with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question