jQuery - AJAX
AJAX [ Asynchronous JavaScript and XML ]
中文
非同步的 JavaScript與 XML
作用
前端與後端
如何jQuery使用AJAX
後端的功能方法
HTTP Request
$.ajax({
url: '/accounts/GetAccounts',
type: 'GET',
success: function (res) {
for (var index = 0; index < res.length; index++) {
var item = document.createElement("option")
item.value = res[index].code
item.text = res[index].name
$("#accounts-options").append(item)
}
},
error: function (e1) {
console.log('======')
console.log(e1.status) //假設URL 錯誤 ==>404
}
})
POST
var data = {
'accountName': $("#account-name").val(),
'accountDescription': $("#account-description").val(),
'currencyCode': $('#account-currrncyCode').val()
}
$.ajax({
url: '/Accounts/Create',
type: 'POST',
data: data,
success: function (res) {
console.log(res) }
})
Comments
Post a Comment