gpt4 book ai didi

javascript - jquery 序列化和 encodeURIComponent

转载 作者:搜寻专家 更新时间:2023-11-01 04:11:34 25 4
gpt4 key购买 nike

我需要对表单输入进行 URI 编码,然后用一堆隐藏的输入序列化并发送到 PHP 文件。是否有可能以某种方式将 encodeURIComponent 组合到这一行中?:

var landingCreate = $(this).serialize();

更新:

例如这样做:

var landingCreate = $(this).serialize()+"&enc="+encodeURIComponent($('input[name=\'longform\']').val());

并输入网址:

http://www.smashingmagazine.com/2008/10/13/pricing-tables-showcase-examples-and-best-practices/

进入文本框,返回 URL 不变..它不应该将所有破折号和斜杠等转换为十六进制代码吗?

更新

这是完整的代码。

<form id="createTokenLanding">
<input type="text" name="longform" />
<input type="hidden" name="domain" value="<?php echo rawurlencode($_SERVER['HTTP_HOST']); ?>" />
<input type="hidden" name="useragent" value="<?php echo rawurlencode($_SERVER['HTTP_USER_AGENT']); ?>" />
<input type="hidden" name="ip" value="<?php echo rawurlencode($_SERVER['REMOTE_ADDR']); ?>" />
<input type="hidden" name="cookieuser" value="<?php echo rawurlencode($_COOKIE['littlr_user']); ?>" />
<input type="submit" name="submit" value="Shorten" />
</form>

<div id="result">
123
</div>

<script type="text/javascript">
$(document).ready(function(){
$.ajaxSetup ({ cache: false });
$('#createTokenLanding').submit(function() {
var landingCreate = $('#createTokenLanding').serialize();
$.ajax({
url: 'action-create.php',
data: landingCreate,
success: function(responseText){
$('#result').html(responseText);
}
});
return false;
});
});
</script>

最佳答案

如果您使用 jQuery.ajax,您可以查看“传统”选项的文档。此外,如果您使用 jQuery 1.4,则在“jQuery.param”中具有“传统”。他们所做的是对键和值使用函数“encodeURIComponent”:

param = encodeURIComponent (key) + "=" + encodeURIComponent (value);

find traditional setting
jQuery.param

更新

从这个例子可以看出,“serialize”对通过post或get发送的字段效果很好。你能把你发送数据的ajax代码放上去吗? example

关于javascript - jquery 序列化和 encodeURIComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4277758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com