FormData: Why does the URL appear undefined?

0

The idea is to take the value from the input [name="path"] and use it as the url value of the method AJAX. But my console is showing that this value is Undefined .

I could not figure out why yet.

My HTML:

<a class="rtrn-conteudo" objeto="form_objeto">Logout</a>
<form id="form_objeto">
	<input type="hidden" name="flag" value="logout"/>
	<input type="hidden" name="caminho" value="meu/caminho/aqui.nesse.formato"/>
</form>

My JQuery:

$(document).ready(function() {
  $("body")
    .on("click", ".rtrn-conteudo", function(event) {

      var objeto = new FormData(document.querySelector("#" + $(this).attr("objeto")));

      $.ajax({
        url: objeto["caminho"], //Detalhe: se eu usar "meu/caminho/aqui.nesse.formato" escrito direto, funciona.
        data: objeto,
        type: 'post',
        processData: false,
        contentType: false,
        success: function(retornoDados) {
          $("body").html(retornoDados);
        }
      });
    });
});
    
asked by anonymous 04.06.2018 / 19:05

1 answer

0

To get the value in formData use get

url: objeto.get("caminho")

You can read more about this documentation

To fill formData you can also do this:

var objeto = new FormData(document.getElementById('form_objeto'));

In this way you would not have to have an "object" attribute with the id of form

    
04.06.2018 / 19:49