如何使用JavaScript设置Content-Type标题 [英] How to set the Content-Type header using JavaScript

查看:200
本文介绍了如何使用JavaScript设置Content-Type标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript将Content-Type标题设置为application / x-www-form-urlencoded; charset = UTF-8?我需要 这样做,我可以查看一个法国字符的表单,而不会产生错误。



谢谢

解决方案

头文件由服务器将内容类型作为HTTP消息的一部分进行设置。当它在浏览器中并运行javascript时,这太迟了。你有权访问服务器端代码吗?为什么不在内部设置内容类型为utf-8?您也可以将它作为头部元标记的一部分。


How can you set the Content-Type header to "application/x-www-form-urlencoded; charset=UTF-8" using JavaScript?

I need to do this so I can view a form with french characters without generating errors.

Thanks

解决方案

Headers are set by the server delivering the content-type as part of the HTTP message. By the time it's in the browser and running the javascript it's too late. Do you have access to the server-side code? Why not set the content type to utf-8 in there? You can also do it as part of the meta tag in the head.

这篇关于如何使用JavaScript设置Content-Type标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆