加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax数据传输中的两种数据类型(String JSON)

发布时间:2020-12-16 01:56:00 所属栏目:百科 来源:网络整理
导读:String 类型的数据传输: $.ajax({ url: 'api.php',type: 'POST',//dataType: 'json',data:$('#network-baozhuang-post').serialize(),}) .done(function(data) { console.log("success",data); if (data data == 'ok') { var tpl = $('#submit-success').ht

String 类型的数据传输:

                $.ajax({
                  url: 'api.php',type: 'POST',//dataType: 'json',data:$('#network-baozhuang-post').serialize(),})
                .done(function(data) {
                  console.log("success",data);
                  if (data  && data == 'ok') {
                    var tpl = $('#submit-success').html();
                    layer.alert(tpl);
                    layer.title('温馨提示');
                  }else{                   
                    var tpl = $('#submit-fail').html();
                    layer.alert(tpl);
                    layer.title('温馨提示');
                  }
                })
                .fail(function() {
                  console.log("error");
                  alert('请求失败');
                })
                .always(function() {
                  console.log("complete");
                });

JSON类型的数据传输:
      var card = $('#inquiry-01-input-1').val();
          $.ajax({
                  url: 'api.php',dataType: 'json',data: {
                    card: card
                  },})
            .done(function(data) {
                  console.log("success",data);
                  if (!data.msg) {
                    console.log("*******");
                    info = "********";
                    showInfoTag(obj,info,isThow);
                  } else {
                    console.log("填写正确");
                  }
            })
            .fail(function() {
                  console.log("error");
                  alert('请求失败');
                })
                .always(function() {
                  console.log("complete");
            });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读