Ajax的contentType属性怎么使用
展开全部
contentType,默认值:?"application/x-www-form-urlencoded"。
意思是“发送信息至服务器时内容编码类型”,其默认值适合大多数情况。
如果你明确地传递了一个?content-type?给?$.ajax()?那么它必定会发送给服务器。
大多数情况不用重新指定,如果遇到乱码的问题,可以考虑添加一下参数,如:application/x-www-form-urlencoded后面加上;?charset=UTF-8
contentType:"application/x-www-form-urlencoded;?charset=UTF-8"
“response”的“contentType” 几种类型是什么?
展开全部
ajax开发中在请求服务器端的响应时, 对于每一种返回类型 规范的做法是要在服务端指定response的contentType
常遇到下面的几种情况:
1、 服务端需要返回一段普通文本给客户端,Content-Type="text/plain"
2 、服务端需要返回一段HTML代码给客户端 ,Content-Type="text/html"
3 、服务端需要返回一段XML代码给客户端 ,Content-Type="text/xml"
4 、服务端需要返回一段javascript代码给客户端
5 、服务端需要返回一段json串给客户端
我们主要讨论返回javascript代码和Json对象的情况。
javascript 的 contentType 按最标准的写法 应该是 application/javascript。
而常用的
text/javascript 已经被 rfc定义为废弃的。
但是 在这里暂时不建议使用 application/javascript . 大家还是继续使用 text/javascript
为好. 因为很多老旧浏览器并不支持 application/javascript .
而所有浏览器都支持text/javascript. 在标准和广泛的兼容性之间 还是暂且选择后者吧。
json 的 contentType 常见写法有 : text/json &
text/javascript .
但是 这个 text/json 其实是根本不存在的, 而 text/javascript 在有些时候客户端处理起来会有歧义.
对于json的contentType , rfc里定义的标准写法是 :application/json.
在这里毫无疑问 我们应该选择标准写法的 application/Json。
response.contenttype的用法是什么啊??
不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 text/html 也就是网页格式.
代码如:
<% response.ContentType ="text/html" %>
<!--#i nclude virtual="/ContentType.html" -->
显示的为网页,而
<% response.ContentType ="text/plain" %>
<!--#i nclude virtual="/sscript/ContentType.html" -->
则会显示html原代码.
以下为一些常用的 ContentType
GIF images
<% response.ContentType ="image/gif" %>
<!--#i nclude virtual="/myimage.gif" -->
JPEG images
<% response.ContentType ="image/jpeg" %>
<!--#i nclude virtual="/myimage.jpeg" -->
TIFF images
<% response.ContentType ="image/tiff" %>
<!--#i nclude virtual="/myimage.tiff" -->
MICROSOFT WORD document
<% response.ContentType ="application/msword" %>
<!--#i nclude virtual="/myfile.doc" -->
RTF document
<% response.ContentType ="application/rtf" %>
<!--#i nclude virtual="/myfile.rtf" -->
MICROSOFT EXCEL document
<% response.ContentType ="application/x-excel" %>
<!--#i nclude virtual="/myfile.xls" -->
MICROSOFT POWERPOINT document
<% response.ContentType ="application/ms-powerpoint" %>
<!--#i nclude virtual="/myfile.pff" -->
PDF document
<% response.ContentType ="application/pdf" %>
<!--#i nclude virtual="/myfile.pdf" -->
ZIP document
<% response.ContentType ="application/zip" %>
<!--#i nclude virtual="/myfile.zip" -->
JSP contentType属性的作用
Content-Type,内容类型,一般是指网页中存在的Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是经常看到一些网页点击的结果却是下载到的一个文件或一张图片的原因。
Content-Type 是什么意思 要通俗易懂
Content-Type,内容类型,一般是指网页中存在的Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是经常看到一些Asp网页点击的结果却是下载到的一个文件或一张图片的原因。
HTML
<meta content="text/html; charset=gb2312" http-equiv="Content-Type"/>
content
即为类型,具体参照下文的“ContentType的类型”
charset
决定网页的编码,一般为gb2312、UTF-8等