me sale el error: Uncaught SyntaxError: Unexpected token

publicado por: Anonymous

En la línea var order = {$cargo.val();} me sale el error:

Uncaught SyntaxError: Unexpected token .

_x000D_

_x000D_

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

_x000D_

_x000D_

_x000D_

solución

La variable order la declaras como objeto y recuerda que un objecto debe llevar un key y un value, propiedad y valor esto te puede servir.

_x000D_

_x000D_

var $cargo = $('#cargo');_x000D_
 var order = {cargo:$cargo.val()};_x000D_
 console.log(order)

_x000D_

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<input type="text" id="cargo" value="valor">

_x000D_

_x000D_

_x000D_

Respondido por: Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *