_mercury
_mercury2y ago

✅ – _mercury – 21-58 Dec 25

what could by the reason that this func sends 2 reqs ?
async saveProduct(cartoon) {
this.order.err = null;
this.order.success = null;
const response = await fetch(
'/orders/{{ $order->id }}/add-product-to/' + cartoon.number, {
method: 'POST',
headers: {
'X-CSRF-Token': document.querySelector('input[name=_token]')
.value
},
body: JSON.stringify(this.order)
});
if (response.ok) {
this.order.success = true;
this.order.err = null;
const product = await response.json();
const activeCartoon = this.order.cartoons.find(c => c.number == cartoon
.number);
// console.log(product);
activeCartoon.products.push({
number: product.packed_by_mfg_serial ? product.mfg_serial :
product.serial,
name: product.product
});
}
async saveProduct(cartoon) {
this.order.err = null;
this.order.success = null;
const response = await fetch(
'/orders/{{ $order->id }}/add-product-to/' + cartoon.number, {
method: 'POST',
headers: {
'X-CSRF-Token': document.querySelector('input[name=_token]')
.value
},
body: JSON.stringify(this.order)
});
if (response.ok) {
this.order.success = true;
this.order.err = null;
const product = await response.json();
const activeCartoon = this.order.cartoons.find(c => c.number == cartoon
.number);
// console.log(product);
activeCartoon.products.push({
number: product.packed_by_mfg_serial ? product.mfg_serial :
product.serial,
name: product.product
});
}
11 Replies
ScriptyChris
ScriptyChris2y ago
Where do you see 2 requests?
_mercury
_mercury2y ago
network tab and they are from this func
ScriptyChris
ScriptyChris2y ago
What is HTTP method in first request - OPTIONS maybe?
_mercury
_mercury2y ago
Both are POST
ScriptyChris
ScriptyChris2y ago
Can you put console.log in saveProduct function's first line to make sure the function gets called only once?
_mercury
_mercury2y ago
_mercury
_mercury2y ago
Called twice
ScriptyChris
ScriptyChris2y ago
What calls that function?
_mercury
_mercury2y ago
mmm i will check Yes that was the issue Smashed
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1056692432663752734
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1056692432663752734 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26