Last active
April 12, 2020 16:43
-
-
Save Jamp/ca7ca9cf6e987e318912e2797ce2688a to your computer and use it in GitHub Desktop.
Ejemplo simple de como hacer solicitudes con sincronas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Update Productos</title> | |
</head> | |
<body> | |
<!-- Código simple para hacer solicitudes sincronas --> | |
<script> | |
const URL = 'https://jsonplaceholder.typicode.com/posts'; | |
const ids = [ | |
1, | |
2, | |
3 | |
]; | |
ids.forEach(async productId => { | |
const result = await fetch(`${URL}/${productId}`, { method: 'GET' }) // Aquí espera que haga una petición completa | |
console.log(result) | |
}); | |
</script> | |
<!-- Código simple para hacer solicitudes sincronas --> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#update_all').click(async (event) => { | |
event.preventDefault(); | |
var opcion = confirm("Esta seguro de actualizar todos los precios, este proceso demorará algunos minutos"); | |
if (opcion == true) { | |
$('#modal_update_status').html(''); | |
$('#modal_update').modal(); | |
for (let index = 0; index < products.length; index++) { | |
const product = products[index]; | |
const URL = base_url + 'calculator/' + product.cont + '/update_prestashop/' + product.id | |
const result = await fetch(URL, { method: 'GET' }) // Aquí espera que haga una petición completa | |
console.log(result) | |
$('#modal_update_status').append('Producto id: ' + p.id + ' actualizado <br>') | |
} | |
} else { | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment