[英]How can I use spaces in a form input's user entered value with jQuery .serializeArray and PHP?
I have a form element and I use this (abbreviated), 我有一个表单元素,我使用了它(缩写),
var dataArray = $(this).serializeArray(),
dataObj = {};
$(dataArray).each(function(i, field){
dataObj[field.name] = field.value;
});
I then use that data with Ajax, sending it to a PHP page (abbreviated). 然后,我将这些数据与Ajax一起使用,并将其发送到PHP页面(缩写)。
url: '/api/controller/name/' + dataObj['guys-name']
If I enter this (minus quotes), 如果输入此数字(减去引号),
The lazy brown fox
懒惰的棕色狐狸
It is submitting like this, which I understand because it has spaces %20, 它是这样提交的,据我了解,因为它有%20的空格,
The%20lazy%20brown%20fox
But when I use print_r()
I get this, 但是当我使用
print_r()
我得到了,
Array
(
[0] => thelazybrownfox
)
I need this so someone can enter a name in one line like smith john. 我需要这个,以便有人可以像史密斯·约翰这样在一行中输入名称。 I can make two form inputs, but that is not what I want to do.
我可以输入两个表单,但这不是我想要的。
URL strings browser transform using Punycode . URL字符串浏览器使用Punycode进行转换。 Right way Correct way is to use the GET or POST parameters.
正确的方法正确的方法是使用GET或POST参数。
$.post( "/api/controller/name/", { name: dataObj['guys-name'] } );
Or decode string "The%20lazy%20brown%20fox" from Punycode. 或从Punycode解码字符串“%20lazy%20brown%20fox”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.