I need to URI encode a form input, that is then serialized with a bunch of a hidden inputs and sent to a PHP file.. is it possible to somehow combine encodeURIComponent into this line?:
var landingCreate = $(this).serialize();
UPDATE:
Doing this for example:
var landingCreate = $(this).serialize()+"&enc="+encodeURIComponent($('input[name=\'longform\']').val());
and entering the url:
http://www.smashingmagazine.com/2008/10/13/pricing-tables-showcase-examples-and-best-practices/
into the text box, returns the URL unchanged.. shouldnt it be converting all the dashes and slashes etc to hex codes?
UPDATE
Here is the full code.
<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>
if you use jQuery.ajax, you can see the documentation for the option "traditional." Also if you use jQuery 1.4 has the "traditional" in "jQuery.param." what they do is use the function "encodeURIComponent" for the key and value:
param = encodeURIComponent (key) + "=" + encodeURIComponent (value);
find traditional setting
jQuery.param
UPDATE
you can see from this example, "serialize" works well over the fields to be sent by post or get. Can you put the ajax code to which you send data? example
Can you try urlencode function and use .replace() for hex codes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With