`$('#form')。serialize()`混淆了UTF-8字符 [英] `$('#form').serialize()` messes up UTF-8 characters

查看:118
本文介绍了`$('#form')。serialize()`混淆了UTF-8字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AJAX插入一个表单,我使用: $('#form')。serialize()获取所有输入并发送到insert.php。



问题是像á这样的字符变成%A9 等等。



如何在发送之前防止这种情况发生,或者如何通过$ _POST获取正确的字符,以便我可以插入他们正确地到我的数据库?



编辑-----



Btw:没有AJAX的表单,只是action =POST到SAME insert.php插入正确,所以问题只是使用serialize()搞乱了HTML。

解决方案

Jquery serialize()序列化为UTF-8。所以á成为正确的UTF-8编码%c3%a1 。尝试使用 $ _ REQUEST ,因为已按照php文档解码。 here


I'm inserting a form with AJAX and I'm using: $('#form').serialize() to get all the input and send it to insert.php.

The problem is that characters like á become %A9 and such.

How can I prevent this from happening before sending it or how get the correct characters when I retrieve it through $_POST so I can insert them correctly to my database?

EDIT -----

Btw: Same Form with no AJAX, just action="POST" to the SAME insert.php inserts correctly, so the problem is solely with serialize() messing the HTML.

解决方案

Jquery serialize() serializes as UTF-8. So á becomes the correct UTF-8 encoding %c3%a1. Try using the $_REQUEST as that is already decoded as per the php documentation. here

这篇关于`$('#form')。serialize()`混淆了UTF-8字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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