I get the error: Uncaught SyntaxError: Unexpected token

0

On line var order = {$cargo.val();} I get the error:

  

Uncaught SyntaxError: Unexpected token.

<script type="text/javascript">
     var $cargo = $('#cargo');
    var order = {$cargo.val();};
 $('#idBoton').on('click' function(){
    fetch('http://181.61.221.52:8119/operative/simplecreateticket/', {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({"auth_key": "ffa07465e5af0a0f69d776e3a288dea1", order}),
    })
    .then(response => response.json()) // response.json() returns a promise
    .then((response) => {
      console.log("You saved this item", response); //returns the new item along with its ID
    })
}
 </script>
    
asked by Alexander aguilar 18.07.2018 в 19:11
source

2 answers

0

The variable order you declare as an object and remember that an object must have a key and a value , property and value this can serve you.

var $cargo = $('#cargo');
 var order = {cargo:$cargo.val()};
 console.log(order)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="cargo" value="valor">
    
answered by 18.07.2018 / 19:47
source
0

You have saved this item {response_key: "c23603c223032a4b4653fe49c80191f4dfa88e6a", ERROR: "The contact name must be entered", VAL: "0"} and the button does not work I have to use it by console

<html>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
   
<script type="text/javascript">
 var $entidad = $('#entidad');
 var order_ent = {order_ent:$entidad.val()};
 var $name = $('#name');
 var order_name = {order_name:$name.val()};
 var $cedula = $('#cedula');
 var order_cedula = {order_cedula:$cedula.val()};
 var $mail = $('#mail');
 var order_mail = {order_mail:$mail.val()};
 var $phone = $('#phone');
 var order_phone = {phone:$phone.val()};
 var $fax = $('#fax');
 var order_fax = {order_fax:$fax.val()};
 var $dir = $('#dir');
 var order_dir = {order_dir:$dir.val()};
 var $city = $('#city');
 var order_city = {order_city:$city.val()};
 var $cargo = $('#cargo');
 var order_cargo = {order_cargo:$cargo.val()};
 var $description = $('#description');
 var order_description = {order_description:$description.val()};
 console.log(order_description,order_dir,order_cargo,order_city,order_fax,order_cedula,order_mail,order_ent)
    
 $('#idBoton').click( function(){   
   
    fetch('http://181.61.221.52:8119/operative/simplecreateticket/', {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({"auth_key": "ffa07465e5af0a0f69d776e3a288dea1", 
   order_ent: $( "entity_number"), order_cedula: $("contact_identification"),
   order_name: $( "contact_name"),
    order_mail: $("contact_email"),
    order_phone: $("contact_phone"),
    order_fax: $("contact_fax"),
    order_dir: $("contact_address"),
   order_city: $("city_name") ,
   order_cargo: $( "contact_position_name"),
    order_description: $("description" ) })
   })
    .then(response => response.json()) // response.json() returns a promise
    .then((response) => {
      console.log("You saved this item", response); //returns the new item along with its ID
    })
});
 </script>
</head>

<body>
<p id="server"></p>
    <div id="informacion">
        <ul></ul>
       <button id="clave"></button>
    </div>

<div id="informacion_2">
     <ul></ul>
<input type="number" id="entidad" value="valor">
<input type="text" id="nombre" value="valor">
<input type="number" id="cedula" value="valor">
<input type="mail" id="mail" value="valor">
<input type="number" id="phone" value="valor">
<input type="number" id="fax" value="valor">
<input type="text" id="dir" value="valor">
<input type="text" id="city" value="valor">
<input type="text" id="cargo" value="valor">
<input type="text" id="description" value="valor">

</div>
 <button type="button" id="idBoton" class="btn btn-primary" >envio</button>
</body>
</html>
    
answered by 18.07.2018 в 21:52