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"); });原文链接:https://www.f2er.com/ajax/163151.html