<script>
$.ajax({
    type: "POST",
    url: "http://localhost:3000/xot/us/confirm",
    crossDomain: true,
    dataType : 'json',
    contentType: "application/json; charset=utf-8",
    data:JSON.stringify({
      username:"User"
    }),
    success: function(result, status, xhr) {
      console.log(result.address1);
    },
    error: function(xhr, status, error) {
      console.log(error);
    }
  })
</script>
-3
marcosegigu 4 nov. 2019 à 19:10

1 réponse

Si vous utilisez nodejs comme backend, vous devez y ajouter un en-tête

app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header(
    'Access-Control-Allow-Headers',
    'Origin, X-Requested-With, Content-Type, Accept'
);
next();  
});

Et dans Ajax Request .. Votre requête ressemblera à ceci

    $.ajax({
    type: "GET",
    url: "http://localhost:3002/category",
    crossDomain: true,
    contentType: "application/json; charset=utf-8",
    data:JSON.stringify({
    username:"User"
    }),
    success: function(result, status, xhr) {
    console.log(result);
    },
    error: function(xhr, status, error) {
    console.log(error);
    }
    })
0
user5943862 4 nov. 2019 à 16:39