Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Passing object in a string using Javascript

I am trying to send to and from objects through string via xhr API call. These objects are defined as follows: (I've even wrapped properties in double quotes but in vain)

const to = {
        name: toName,
        address_line1: toAddres_line1,
        address_city: toCity,
        address_state: toState,
        address_zip: toZip
    };
    const from = {
        name : fromName,
        address_line1 : fromAddres_line1,
        address_city : fromCity,
        address_state : fromState,
        address_zip : fromZip
    };
var data = "to={" + to + "}&from={" + from + "}&color=false";  

tried removing spaces between " + to + " to "+to+" but no luck

While sending the property values inside data variable it is not getting passed properly. Upon console.log(to); and console.log(from); it gives me the right declaration of the objects in console which is as to={[object Object]}

Following error is thrown upon sending data to server by ```:

{
    "error": {
        "message": "from address not found",
        "status_code": 404,
        "code": "not_found"
    }
}

I tried searching if I'm passing the objects in a wrong way but couldn't hit a luck now. So, I am unable to find what is exactly wrong in my code.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda