分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

Jquery的Ajax中contentType和dataType的区别

发布时间:2023-09-06 01:27责任编辑:沈小雨关键词:Ajax

上代码

$.ajax({ ???type: httpMethod, ???cache:false, ???async:false, ???contentType: "application/json; charset=utf-8", ???dataType: "json",//返回值类型 ???url: path+url, ???data:jsonData, ???success: function(data){ ???????var resultData = ‘返回码=‘+data.status+‘,响应结果=‘+data.message+‘,耗时=‘+data.tcost; ???????layer.msg(resultData,{icon: 1}); ???}, ???error : function(xhr, ts, et) { ???????layer.msg(‘服务调用失败!‘, {icon: 2}); ???}});

区分:

contentType: 发送信息至服务器时内容编码类型,简单说告诉服务器请求类型的数据

   在调试js时候通过chrome的F12或firefox的firebug查看请求参数时,尤其请注意head

   默认值: "application/x-www-form-urlencoded"

dataType:告诉服务器,我要想什么类型的数据,除了常见的json、XML,还可以指定 html、jsonp、script或者text

  

Jquery的Ajax中contentType和dataType的区别

原文地址:http://www.cnblogs.com/huahua035/p/7922136.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved