Please I need help I am stuck in this since yesterday, the probleme is I got a numberInput I use jquery autocomplete that helps me select a user's subscription number. With that number I want to get the full name of a user and show it on the twig. I am calling the JS function getInfoOfInput() once my input is changed, these are the JS function that I use:
function getInfoOfInput()
{
var tutoreSelectionne = document.getElementById("numAdherent");
var tutore = tutoreSelectionne.value;
//alert(tutoreSelectionne.value);
recupName(tutore);
}
function recupName(tutoreSelectionne) {
var DATA = {tutoreSelectionne: tutoreSelectionne};
var request = $.ajax({
type: "POST",
url: "{{ path('paces_statistique_default_getnometprenomtutore') }}",
data: DATA,
success: function(data){
$('#name').html(data);
}
});
return false;
}
This is the function in my controller :
/**
* get fullName
* @Secure(roles="ROLE_ADMIN")
* @Route("/recupFullName/")
* @param Request $request La requête ajax qui envoie le numAd
* @return Response $fullnam
*/
public function getNomEtPrenomTutore($request){
$em = $this->getDoctrine()->getManager();
$tutoRepo = $em->getRepository(Tutore::class);
if ($request->isXmlHttpRequest()) {
$numTutore = $request->request->get('tutoreSelectionne');
$tutore = $tutoRepo->findOneBy(['username' => $numTutore]);
$nom = $tutore->getNom();
$prenom = $tutore->getPrenom();
$fullName = "$nom $prenom";
return $this->render("PACESStatistiqueBundle:Default:index.html.twig", array('fullName'=>$fullName));
}
}
PS: The 'username' is the user's subsription number ^^ I know it's not the good the name to use for it.
My input on the twig :
<div class="ui-autocomplete-input">
<input type="number" id="numAdherent" value="" onchange="getInfoOfInput();" onkeyup="this.onchange();" oninput="this.onchange();" onautocomplete="this.onchange();">
</div>
I use this to override the value of the input when I change it
// INPUT VALUE OVERRIDE
$(function () {
{% if is_granted('ROLE_ADMIN') %}
$('td input[id^=numAdherent]').each(
function (){
$(this).on("change paste keyup", function()
{$(this).attr('value', $(this).val())})
}
);
{% endif %}
});
this is the error that I get In JS with "Inspect Element"
jquery-1.11.3.min.js:5 POST http://localhost:8000/recupFullName/ 500(Internal Server Error)
send @ jquery-1.11.3.min.js:5
ajax @ jquery-1.11.3.min.js:5
recupName @ vueStatistique:231
getInfoOfInput @ vueStatistique:226
onchange @ vueStatistique:276
oninput @ vueStatistique:276
Thank you in advance for any help you can give me :)
1 Answer 1
Internal Server Error normally means, that something is not right in your controller action.
$tutore = $tutoRepo->findOneBy(['username' => $numTutore]);
This line might be the problem. For me, username does not sound like a number. Is this line really correct?
Edit: After checking the error message, here is the solution: Change
public function getNomEtPrenomTutore($request){
to
public function getNomEtPrenomTutore(Request $request){
and make sure that you actually import the Request class.
4 Comments
Preview tab to see the server response (aka the error message) rendered as html.