How to send Json via fetch construct and track if it went away?

  • 0
    I'm trying to send json to the server through the fetch construction and get a response in the form of jsona with translation. But for some reason the json is not being sent. maybe I missed something? How can you track in the browser whether json went away with the request or not?

    let map= new Map([["80-c4-48-84-79", " Federal research and production center "],
    ["73-b3-49-af-9d"," dgru"],
    ["04-d2-45-86-6a","Main"],
    ["d0-51-41-bf-4f", " Publications"],
    ["c5-3c-4d-83-4f", " news"],
    ["7d-ae-46-a0-25", "Contacts"],
    ["8f-01-4b-81-4e", "Certification center"],
    ["56-32-40-82-1a","1959"],
    ["27-63-47-b9-1c","2019"],
    ["a7-34-46-b8-38"," Moscow"],
    ["42-29-4c-bb-df"," text"],
    ["67-8b-47-b1-34","example"]]);
    //let s =  JSON.stringify({ room: Object.fromEntries(map) })
    //console.log(s)
    
    fetch("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=ru&hl=ru&dt=t&dt=bd&dj=1&source=icon&tk=467103.467103&q=", {
        method: 'POST',
        headers: {
          "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
        },
        body: JSON.stringify({ room: Object.fromEntries(map) })
    })
    .then(function(response){
        return response.text();
    })
    .then(function(text){
        console.log(text);
    })


    CONCLUSION
    {"src":"ru","confidence":0.0,"spell":{},"ld_result":{"srclangs":["ru"],"srclangs_confidences":[0.0],"extended_srclangs":["ru"]}}


    And it should be something like this.
    {"sentences":[{"trans":"{\"room\": {\"80-c4-48-84-79\": \"Федеральный научно-производственный центр\", \"73-b3-49-af-9d\": \"dgru\", \"04-d2-45-86 ","orig":"{\"room\":{\"80-c4-48-84-79\":\" Federal research and production center \",\"73-b3-49-af-9d\":\" dgru\",\"04-d2-45-86","backend":3,"model_specification":[{}],"translation_engine_debug_info":[{"model_tracking":{"checkpoint_md5":"cce7c67b3f2439089dd6b428e0b83b88","launch_doc":"en_ru_2020q2.md"}}]},{"trans":"-6a »:« Главная »,« d0-51-41-bf-4f »:« Публикации »,« c5-3c-4d-83-4f »:« новости »,« 7d-ae-46-a0-25 ","orig":"-6a\":\"Main\",\"d0-51-41-bf-4f\":\" Publications\",\"c5-3c-4d-83-4f\":\" news\",\"7d-ae-46-a0-25","backend":3,"model_specification":[{}],"translation_engine_debug_info":[{"model_tracking":{"checkpoint_md5":"cce7c67b3f2439089dd6b428e0b83b88","launch_doc":"en_ru_2020q2.md"}}]},{"trans":"»:« Контакты »,« 8f-01-4b-81-4e »:« Удостоверяющий центр »,« 56-32-40-82-1a »:« 1959 »,« 27-63-47-b9-1c » ","orig":"\":\"Contacts\",\"8f-01-4b-81-4e\":\"Certification center\",\"56-32-40-82-1a\":\"1959\",\"27-63-47-b9-1c\"","backend":3,"model_specification":[{}],"translation_engine_debug_info":[{"model_tracking":{"checkpoint_md5":"cce7c67b3f2439089dd6b428e0b83b88","launch_doc":"en_ru_2020q2.md"}}]},{"trans":": \"2019\", \"a7-34-46-b8-38\": \"Москва\", \"42-29-4c-bb-df\": \"text\", \"67-8b-47-b1-34\": \" ","orig":":\"2019\",\"a7-34-46-b8-38\":\" Moscow\",\"42-29-4c-bb-df\":\" text\",\"67-8b-47-b1-34\":\"","backend":3,"model_specification":[{}],"translation_engine_debug_info":[{"model_tracking":{"checkpoint_md5":"cce7c67b3f2439089dd6b428e0b83b88","launch_doc":"en_ru_2020q2.md"}}]},{"trans":"пример\"}}","orig":"example\"}}","backend":1}],"src":"en","confidence":0.98975265,"spell":{},"ld_result":{"srclangs":["en"],"srclangs_confidences":[0.98975265],"extended_srclangs":["en"]}}
    JavaScript Aidan Kim, Feb 6, 2019

  • 1 Answers
  • 0
    Judging by the question, the request is definitely going away. And you get a response from the server. But there are no translations in the answer for some reason. Open the debugger. It has the Networks panel. There you can find your request and see detailed information about what is sent and how. And then figure out why the server is not responding there.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!