我有一个完美但只有一次工作的选择选项,请求不会再次执行。
我认为这是因为'onchange'事件。
这是我的ajax代码:
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/>
答案 0 :(得分:1)
你应该映射到
private Static final String MULTIPART_MYME_TYPE="multipart/related";
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
try {
if (isRequest) {
if (context.containsKey("pdf")) {
byte[] arr = (byte[]) context.get("pdf");
SOAPMessage soapMsg = context.getMessage();
soapMsg.getMimeHeaders().addHeader("Content-type", MULTIPART_MIME_TYPE);
AttachmentPart attachment = createAttachment(soapMsg, arr, "test.pdf", context);
soapMsg.addAttachmentPart(attachment);
Iterator<AttachmentPart> it = context.getMessage().getAttachments();
while (it.hasNext()) {
AttachmentPart att = it.next();
System.out.println(att.getContent());
}
System.out.println("ok");
}
}
} catch (Exception e) {
return false;
}
return true;
}
private AttachmentPart createAttachment(SOAPMessage msg, byte[] payload, String fileId, SOAPMessageContext context) {
@SuppressWarnings("unchecked")
Map<String, DataHandler> attachmentsMap = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
ByteArrayDataSource ds = new ByteArrayDataSource(payload, MULTIPART_MIME_TYPE);
DataHandler dh = new DataHandler(ds);
AttachmentPart attachmentPart = msg.createAttachmentPart();
attachmentPart.setContent(new ByteArrayInputStream(payload), MULTIPART_MIME_TYPE);
attachmentPart.setContentId(fileId);
String contentDisposition = "Content-Disposition: attachment; name=\"" + fileId + "\"";
attachmentPart.addMimeHeader("Content-Disposition", contentDisposition);
msg.addAttachmentPart(attachmentPart);
attachmentsMap.put(fileId, dh);
context.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attachmentsMap);
context.getMessage().getAttachments();
return attachmentPart;
}
例如
.on(eventType, selector, function)