Uncaught Error: Syntax error, unrecognized Expression: #botao_resp_<?= $Row['id']? >

Asked

Viewed 546 times

0

I have a page with Formularies to answer questions and I am trying to use jquery in a separate file and is giving the following error: Uncaught Error: Syntax error, unrecognized Expression: #boot_

$("#botao_resp_<?=$row['id']?>").on('click', function (event) {
event.preventDefault();
alert('Você clicou no botão!');

$.ajax({
    method: 'POST',
    url : 'banco-responder.php',
    data: {
    id : $("#id-resposta-<?=$row['id']?>").val() ,
    resposta : $("#resposta-pergunta-<?=$row['id']?>").val()
}
    }).done(function(data){
    console.log($("#card-<?=$row['id']?>").hide());
    alert("Respondido com Sucesso!");
    }).fail(function(){
    alert('Deu pau');
    });
return false;

});

In the form ID attribute is completed by a variable, which comes from iterating an array. When I put this code in the same form file, it works. But when I import it from another file it doesn’t work.

  • That code JS stays in a separate javascript file?

  • Yes, this file is separate.

  • Well, it is possible, but it is not recommended. You can "report" to your server Nginx/Apache read the JS as if it were a PHP, but this creates serious security problems; you can create a code PHP to behave like JS, simply add the header => Content-Type: text/javascript or you can create a global variable in form.html, for example and use it in the file .js.

  • would have another solution other than this? the problem is in the php variable, right?

  • The problem is in using php in the archives .js. Servers by default do not interpret code php in those files. If possible post part of your html gerado so I can post a more complete reply.

  • <form id="form_ocul_<?= $Row['id']? >" style="display: inline-block;" action="" method="post"> <input type="Hidden" id="id-hide-<?= $Row['id']? >" name="id" value="<?= $Row['id'] ? >"> <button class="btn btn-Warning" type="Submit">HIDE</button> </form> This is one of the forms. The ajax was just below and put in another file.

  • I believe that the best solution for this is to join this js code to a file . php

Show 2 more comments
No answers

Browser other questions tagged

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