Bonjour,
j'essaie de construire un objet json format {'aa':'aa','zz':'zz','ee':'ee','list':{{'p1':'ppp','p2','zzz'},{'p1':'pp','p2','z'}} avant l'envoyer à mon action spring mvc.
voir le code ci dessous :
lorsque j'envoie ma requête, j'obtient une erreur 405. mon objet json construit est:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 function enregistrerCommande(){ var data={}; data['numeroContrat']= $('#numeroContrat').val(); data['numeroCommande']= $('#numeroCommande').val(); data['objet']= $('#objet').val(); data['description']= $('#description').val(); var detailsCommande=[]; for(i=0;i<=compteur;i++){ var detail ={}; detail['typeProduit']=$('#typeProduit'+i).val(); detail['quantite']=$('#quantite'+i).val(); detail['prix']=$('#prixunit'+i).val(); detailsCommande.push(detail); } var detailsCommandeForm = JSON.stringify(detailsCommande); data['detailsCommandeForm']=detailsCommandeForm; console.log(JSON.stringify(data)); $.ajax({ type:'post', contentType: 'application/json', data:JSON.stringify(data), dataType: 'json', url:'${pageContext.request.contextPath}/saisircommande/enregistrer', success:function(response){ console.log(response); }, error:function(response){ alert('error'); } }); }
je pense que le format de mon objet json qui cause cette erreur.{"numeroContrat":"1","numeroCommande":"ff","objet":"sdds","description":"fdfsd","detailsCommandeForm":"[{\"typeProduit\":\"1\",\"quantite\":\"1\",\"prix\":\"2\"}]"}
comment faire pour qu'il soit au format mentionné ci dessus ?
Merci.
Partager