ajax请求中contentType与dataType含义【data-id,target.dataset.id,var target = e.currentTarget;】

contentType: 告诉服务器,我要发什么类型的数据

dataType: 'json',:我要接受什么类型的数据

 属性    data-id=“222”;

var target = e.currentTarget;

target.dataset.id 值为 222。

 

 1     $('.category-wrap').on('click', '.row-product-category.now .delete',
 2             function(e) {
 3                 var target = e.currentTarget;
 4                 $.confirm('确定么?', function() {
 5                     $.ajax({
 6                         url : deleteUrl,
 7                         type : 'POST',
 8                         data : {
 9                             productCategoryId : target.dataset.id,
10                             shopId : ''
11                         },
12                         dataType : 'json',
13                         success : function(data) {
14                             if (data.success) {
15                                 $.toast('删除成功!');
16                                 getlist();
17                             } else {
18                                 $.toast('删除失败!');
19                             }
20                         }
21                     });
22                 });
23             });
 1 $.ajax({
 2             url : addUrl,
 3             type : 'POST',
 4             data : JSON.stringify(productCategoryList),
 5             contentType : 'application/json',
 6             success : function(data) {
 7                 if (data.success) {
 8                     $.toast("提交成功!");
 9                     getlist();
10                 } else {
11                     $.toast("提交失败!");
12                 }
13             }
14         });

猜你喜欢

转载自www.cnblogs.com/gzhli/p/8991414.html