我需要URI編碼形式的輸入,也就是,然後用一束的隱藏的輸入串行化並將其發送到一個PHP文件..是有可能以某種encodeURIComponent方法結合成此行?:jquery的序列化和encodeURIComponent方法
var landingCreate = $(this).serialize();
UPDATE:
這樣做,例如:
var landingCreate = $(this).serialize()+"&enc="+encodeURIComponent($('input[name=\'longform\']').val());
並輸入URL:
http://www.smashingmagazine.com/2008/10/13/pricing-tables-showcase-examples-and-best-practices/
進入文本框,返回的URL不變..不應該它將所有破折號和斜槓等轉換爲十六進制代碼?
UPDATE
下面是完整的代碼。
<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>
您想要傳遞URI編碼的輸入是由用戶輸入還是隱藏的輸入? – 2010-11-25 14:22:38
它由用戶輸入。 – Gary 2010-11-25 14:23:56
「longform」的形式是「this」?你正在使用事件提交來發送Ajax數據? – 2010-11-25 15:06:59