开发者

jquery serialize and encodeURIComponent

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开发者_如何学Go 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜