K
K
Kypcant2021-06-18 18:39:25
JavaScript
Kypcant, 2021-06-18 18:39:25

How to call asynchronous function on smartphone?

//////////////////////////////////////////// mail_client.js
export async function SendMessage(name, mailFrom, subject, message){
  var data = {
        service_id: 'сервис',
        template_id: 'шаблон',
        user_id: 'здесь юзер',
        accessToken: "здесь токен",
        template_params: {
            'name': name,
            'mail': mailFrom,
            'message': message,
            'subject': subject
        }
    };
    const headers = {
      "Accept": "application/json",
      'Content-Type': 'application/json; charset=utf-8'
    }
    var isSeccess = false;
    var info =await axios({
        method: 'post',
        url: 'https://url',
        data: JSON.stringify(data),
        headers
      }).then(function (resp) {
        if(resp.data === "OK"){
          isSeccess = true;
        }
        else {
          isSeccess = false;
        }
      });
      return isSeccess;
}

export async function SendMessClickEventHandler(){
  	var name = document.getElementById("user-name");
  	var mail = document.getElementById("user-mail");
  	var message = document.getElementById("user-message");
  	var subject = document.getElementById("user-subject");
  	
        var isSeccess = await SendMessage(name.value, mail.value, subject.value, message.value);
        if(isSeccess){
            name.value = "";
            mail.value = "";
            message.value = "";
            subject.value = "";
            alert("Сообщение успешно отправлено.");
        }
        else{
            alert("Сообщение не отправлено. Попробуйте еще раз.");
        }
}


//////////////////////////////////////////////////////////////////////////////////// function.js
export function SubmitForm(callbackSubmit){
    var submitBt = document.getElementById("submit-but");
    submitBt.addEventListener("mouseover", ()=>{
        submitBt.style.cursor="pointer";
        submitBt.style.color = "#fff";
        submitBt.style.backgroundColor ="#cd192d";
    })
    submitBt.addEventListener("mouseout", ()=>{
        submitBt.style.cursor="default";
        submitBt.style.color = "#cd192d";
        submitBt.style.backgroundColor ="#fff";
    })
    submitBt.addEventListener("click", ()=>{
        submitBt.dispatchEvent(new Event("mouseover")); ///сюда визов доходит
        callbackSubmit();
        setTimeout(() => {
            submitBt.dispatchEvent(new Event("mouseout"));
        }, 250);
    })
}

////////////////////////////////////////////////////////////// index.js
view.SubmitForm(SendMessClickEventHandler);


Greetings Lord.
I wrote a client to send data from the form and in this form it works, but only if from a computer.
From a smartphone, the callback function is not called, I noted where the call reaches, please, share your wisdom and options for solving this problem. Thanks)))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kypcant, 2021-06-19
@Kypcant

I tested with different browsers and found the problem: "ReferenceError: regeneratorRuntime is not defined". I use the Parcel assembler. I solved the problem by adding to index.jsimport 'regenerator-runtime/runtime'

K
Korifa, 2021-06-19
@Korifa

need a special asynchronous smartphone :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question