1. 程式人生 > >筆記,ajax,事件綁定,序列化

筆記,ajax,事件綁定,序列化

刪除 編輯 true get 字符串類 增加 當前頁 del $.ajax

1.
Python序列化
字符串 = json.dumps(對象) 對象->字符串
對象 = json.loads(字符串) 字符串->對象

JavaScript:
字符串 = JSON.stringify(對象) 對象->字符串
對象 = JSON.parse(字符串) 字符串->對象

應用場景:
數據傳輸時,
發送:字符串
接收:字符串 -> 對象
2. ajax

$.ajax({

url: ‘http//www.baidu.com‘,
type: ‘GET‘,
data: {‘k1‘:‘v1‘},
success:function(arg){
// arg是字符串類型
// var obj = JSON.parse(arg)
}
})


$.ajax({
url: ‘http//www.baidu.com‘,
type: ‘GET‘,
data: {‘k1‘:‘v1‘},
dataType: ‘JSON‘,
success:function(arg){
// arg是對象
}
})


$.ajax({
url: ‘http//www.baidu.com‘,
type: ‘GET‘,
data: {‘k1‘:[1,2,3,4]},
dataType: ‘JSON‘,
success:function(arg){
// arg是對象
}
})

發送數據時:
data中的v

a. 只是字符串或數字
$.ajax({
url: ‘http//www.baidu.com‘,
type: ‘GET‘,
data: {‘k1‘:‘v1‘},
dataType: ‘JSON‘,
success:function(arg){
// arg是對象
}
})
b. 包含屬組
$.ajax({
url: ‘http//www.baidu.com‘,
type: ‘GET‘,
data: {‘k1‘:[1,2,3,4]},
dataType: ‘JSON‘,
traditional: true,
success:function(arg){
// arg是對象
}
})

c. 傳字典

b. 包含屬組
$.ajax({
url: ‘http//www.baidu.com‘,
type: ‘GET‘,
data: {‘k1‘: JSON.stringify({}) },
dataType: ‘JSON‘,
success:function(arg){
// arg是對象
}
})



3. 事件委托

$(‘要綁定標簽的上級標簽‘).on(‘click‘,‘要綁定的標簽‘,function(){})

$(‘要綁定標簽的上級標簽‘).delegate(‘要綁定的標簽‘,‘click‘,function(){})

4. 編輯

5. 總結

新URL方式:
- 獨立的頁面
- 數據量大或條目多

對話框方式:
- 數據量小或條目少
-增加,編輯
- Ajax: 考慮,當前頁;td中自定義屬性
- 頁面(***)

刪除:
對話框


筆記,ajax,事件綁定,序列化