javascript post

Asked

Viewed 228 times

0

In my HTML I take this 'Right-Handed' STRING and pass to this JS sendPost()

<tr>
    <td>Destros</td>
    <td><span class="label label-success">${analitico.vitoriasDestro}</span></td>
    <td><span class="label label-danger">${analitico.derrotasDestro}</span></td>
    <td><span>${analitico.totalDestroPercent}%</span></td>
    <td><span class="statusPercent"><a style="display:none">${analitico.totalDestroPercent}</a></span></td>  
    <td><a href="#" onclick="sendPost('relatorio-analitico-a', {id: 'Destro'});"><i class="dripicons-folder-open"></i></a></td>
</tr>

In my JS I should take this 'Right-Handed' STRING and do the post

if (!window.sendPost) {
window.sendPost = function (url, obj) {
    //Define o formulário
    var myForm = document.createElement("form");
    myForm.action = url;
    myForm.method = "post";

    for (var key in obj) {
        var input = document.createElement("input");
        input.type = "text";
        input.value = obj[key];
        input.name = key;
        myForm.appendChild(input);
    }
    //Adiciona o form ao corpo do documento
    document.body.appendChild(myForm);
    //Envia o formulário
    myForm.submit();
};}

However String is arriving in my controller with no value 'NULL'

public ModelAndView analiticoViewA(String receive, HttpSession session, HttpServletRequest request) {
    try {
        UsuarioDTO usuario = (UsuarioDTO) request.getSession().getAttribute("usuarioLogado");
        analiticoDTO.setIdAnalitico(usuario.getIdUsuario());
        usuarioDTO.setIdUsuario(usuario.getIdUsuario());

        System.out.println("imprime :" + receive);
        List<ResultadoDTO> result = analiticoDAO.selecionaAnalitc(receive, usuario.getIdUsuario());
        ModelAndView mv2 = new ModelAndView("relatorio-a");

        mv2.addObject("analitico", analiticoDAO.buscaPorId(analiticoDTO));
        mv2.addObject("dinamico", result);
        mv2.addObject("user", usuarioDAO.buscaPorId(usuarioDTO));

        return mv2;

    } catch (SQLException e) {
        UsuarioDTO usuario = (UsuarioDTO) request.getSession().getAttribute("usuarioLogado");
        capturaException.ExceptionHandlingController(e, usuario);
        ModelAndView mv = new ModelAndView("error-pages/erro-500");
        return mv;
    }
}

Important note is, if I unquote and put a number, the int reaches my controller, if it’s string it’s not enough.

Note: No error in console.

I believe I must be doing something wrong in JS, if someone can visualize something.

  • Something pops up on the console.error()? Try replacing single quotes with double quotes using escape: "Right-handed", it works...

  • Jhonatan didn’t work out :/

  • Open browser console? Ctrl+Shift+i. If you have an error there, add to question

  • no error.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.