Ich habe eine Auswahloption, die perfekt funktioniert, aber nur einmal, die Anfrage wird nicht erneut ausgeführt.Ajax Anfrage funktioniert nur einmal
Ich denke, es ist wegen der 'onchange' Ereignis.
Das ist mein Ajax-Code:
jQuery(document).ready(function($) {
$('#referenceProduit').change(function(){
//on recupere la valeur de l'attribut value pour afficher tel ou tel resultat
var req=$('#referenceProduit').val();
//requête ajax, appel du fichier function.php
$.ajax({
type: "POST",
url: "include/php.php",
data: "referenceProduit="+req,
dataType : "json",
//affichage de l'erreur en cas de problème
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
},
//function s'il n'y a pas de probleme
success:function(data){
//On affiche la réponse du serveur
$('.produit').empty();
$('.produit').prepend(data.produit);
$('input[name="designation"]').val(data.resDisplayForm.designation);
$('input[name="prix"]').val(data.resDisplayForm.prix);
}
});
});
});
HTML-Code:
<div class="form-group">
<label for="referenceProduit" class="col-sm-1 control-label">Reference</label>
<div class="col-sm-2">
<select class="form-control" name="referenceProduit" id="referenceProduit">
<option selected="selected" disabled="disabled">Choisir</option>
<?php foreach($lesProduits as $unProduit){?>
<option name="<?php echo $unProduit['id'];?>" value="<?php echo $unProduit['id'];?>"><?php echo $unProduit['reference']?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<div class="produit"></div>
</div><br/><br/>
Ist das '# referenceProduit' Element im' .produit' Element? (In diesem Fall würde es gelöscht und neu erstellt von Ihrer Erfolgsfunktion, nach denen es keine 'Änderung' Handler haben würde.) – nnnnnn
Alle Fehler protokolliert? – passion
.produit ist das div, wo das Ergebnis angezeigt wird und #referenceProduit der Name meines ausgewählten, so dass es innen sein kann. (bearbeitet) –