jquery傳送ajax請求
阿新 • • 發佈:2019-02-19
POST方式:
$.ajax({ type: "POST", url: 'aaa/bbb', data: JSON.stringify({ aa: 'aa', isdefault: isdefault //name需要和後臺中javabean的屬性名稱嚴格一致 }),//轉換為json字串 async: false, contentType: 'application/json', //json資料提交 dataType: "json", success: function(response) { if (response.code == '0000') {//code 是後臺返回的資料物件的屬性 // alert(response.data.validate); isvalidate = response.data.validate; } } });
GET方式:
$.ajax({ type: "GET", url: 'aa/bb', data: { templateId: tempId, questionId: questionId }, async: false, contentType: 'application/json', dataType: "json", error: function(data) { alert(data.message); }, success: function(response) { // alert(response.code) if (response.code == '0000') { //todo } else { alert("儲存失敗," + response.message); } } });