Answer the question
In order to leave comments, you need to log in
JS IF ELSE in JSON post request, how to implement?
Data comes from the site form, I parse it and get data in json format, then I need to check whether the field is filled or not, if it is filled then pass it on in the post request, if not filled then do nothing.
The input looks like this -
I want to do a check, IF\ELSE.
If form.NAME = noone then nothing
Else "NAME" : form.NAME;
My script looks like this -
//Объявляю переменную
var formname = msg.form.NAME
//Служебная информация метода, url, тип данных
msg.headers = {}
msg.method = "POST"
msg.url = "http://127.0.0.1:1880/tst" ;
msg.headers["content-type"] = "application/json"
//Сам скрипт в msg.payload и есть тело запроса
msg.payload = {
//если formname = noone, то пропускаем и ничего не делаем
if (formname = 'noone') {
//
}
//Иначе добавляем в тело "NAME" : formname
else {
"NAME": formname;
}
// Это просто данные в формате JSON
"PHONE":"+79876543210",
};
//возвращаем в поток
return msg
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question