ajax请求里的contentType: "applicationjson"作用

xiaoxiao2021-02-27  407

对于页面中复杂数据的提交:

$.ajax({ type:"post", url:url, dataType: "json", contentType: "application/json", async:true, data:JSON.stringify(param), success:function(result){ if(result.code == "0"){ var rows = result.data; if(typeof successcallback == 'function'){successcallback(rows);}else{alert(result.msg);} }else{ alert(result.msg); } }, error:function(jqXHR, textStatus, errorThrown){ //alert("提交失败,请重试!"); } });

需要通过JSON.stringify(param)把页面中获取的参数变成json字符串,,此时需要加上contentType: "application/json",

转载请注明原文地址: https://www.6miu.com/read-2482.html

最新回复(0)