首页 > 解决方案 > 我对如何将数据发送到 enpoint 有疑问

问题描述

早上好我有一个问题,我有一个表单对象和一个字段变量,当我用XXX函数发出一个post请求时,它没有设置字段中的值,当我发送到时它会抛出一个basio数组指出。

我分享代码

 async function createForm() {
        try {
        if ( form == null) {
            form = {
            'deviceId'          : deviceId,
            'closeTimestamp'    : undefined,
            'fields'            : [],
         };
        fields.push({
            "id"            : fieldId,
            "startTimestamp": parseInt(Date.now()/1000),
            "stopTimestamp" : undefined,
            "observation"   : null
         })
        console.log('formcreate',form)
         
        }

        const operation =  await createCargoTransport(deviceId, form)
         console.log('data al crear ===>',operation)
         form.id = operation.id;
       
       } catch (e) {
        if ( e.message.includes('not identified') ) {
            fields  = [];
            form    = {};
            clearSession();
        }
     }
      isFormReady = false;
    } 

在谷歌控制台中,我看到它没有将数据保存在字段中

{deviceId:154,字段:[]} deviceId:154 字段:[]

标签: javascriptarraysjavascript-objectssvelte-3

解决方案


推荐阅读