L
L
Leo Mavrin2020-11-20 13:13:46
JavaScript
Leo Mavrin, 2020-11-20 13:13:46

I can't figure out why fetch fails on request?

Wrote a script to accept data from WP and send it to the frontpad (accounting system).
The problem is that I rewrote the packaging logic and fetch seems to send data, but it crashes with an internal error. It does not wait for a response from the server. When using the old code, everything works. The same data, the same fetch, but different packing logic. If there were no data inside at all, the server would return an error that there is no key that I am sending, so that it will let me through. What could be the reason for this behaviour? Help me please).
Old and new code here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twolegs, 2020-11-20
@twolegs

const fullName = () => {
            let fullName = "";

            fullName += billing?.['first_name'] + " ";
            fullName += billing?.['last_name'];

            return fullName;
        };
        ...
        formData.append('name', fullName);

Here you add a function instead of a line to the form, which is probably why.
formData.append('name', fullName() );
But it is not at all surprising that bugs arise with this style of writing code. You have global variables, name overlaps, async and promises. Try to add at least a banal linter with basic rules, it will be a little better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question