프로그래밍/JAVA
Ajax로 요청 값 보내기 - Param, body
by LiveData
2019. 6. 17.
Parameter 로 값 보내기
ex) url?name=test&Age=21 ...
var Parms = '?Channel=mychannel'; Parms += '&Id=example2'; Parms += '&Name=example2'; Parms += '&Age=21'; Parms += '&Sex=m';
$.ajax({ contentType: "application/json; charset=utf-8", type:"post", url: 'http://52.184.39.138:4000/api/v1/balance/saveUser'+Parms, success: function searchSuccess(resp) { console.log(resp); }, error: function searchError(xhr, err) {
console.error("Error on ajax call: " + err); console.log(JSON.stringify(xhr)); } });
|
body에서 josn 형로 보내기
var sendData= { "name":"ee2", "balance" : 3 }
$.ajax({ contentType: "application/json; charset=utf-8", type:"post", dataType:'json', data: JSON.stringify(sendData), url: 'http://52.184.39.138:4000/api/v1/balance/user', success: function searchSuccess(resp) { console.log(resp); }, error: function searchError(xhr, err) { myApp.hidePreloader(); myApp.alert('An error has occurred', 'Search Error'); console.error("Error on ajax call: " + err); console.log(JSON.stringify(xhr)); } });
|