javascript window.location do I need to escape? - Stack Overflow

var delivery_date = $("#year").val()+'-'+$("#month").val()+'-'+$

    var delivery_date = $("#year").val()+'-'+$("#month").val()+'-'+$('#day').val();
    var delivery_time = $("#delivery_time").val();
    var zone = $("#zone").val();
    window.location = window.location+'/'+delivery_date + '/'+ delivery_time + '/'+ zone;

Do I need to escape the parameters in window.location = window.location...etc

zone could be something with spaces, quotes,..etc

    var delivery_date = $("#year").val()+'-'+$("#month").val()+'-'+$('#day').val();
    var delivery_time = $("#delivery_time").val();
    var zone = $("#zone").val();
    window.location = window.location+'/'+delivery_date + '/'+ delivery_time + '/'+ zone;

Do I need to escape the parameters in window.location = window.location...etc

zone could be something with spaces, quotes,..etc

Share Improve this question asked Mar 30, 2011 at 12:52 Chris MuenchChris Muench 18.4k71 gold badges218 silver badges373 bronze badges 2
  • 1 Do you have URL mapping, or did you mean to send those values as query string data to the same page? – user447356 Commented Mar 30, 2011 at 12:56
  • 1 if you want encode url use encodeURIComponent() instead of escaspe() – Luca Filosofi Commented Mar 30, 2011 at 12:57
Add a ment  | 

3 Answers 3

Reset to default 3

You need to properly url-encode the parameters. See here for more information; encodeURIComponent should work fine.

if you want to have the php url_encode and url_decode behaviour use:

function url_encode(str) {
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function url_decode(str) {
    return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}

Use encodeURIComponent.

var zone = encodeURIComponent($("#zone").val());

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744353862a4570132.html

相关推荐

  • javascript window.location do I need to escape? - Stack Overflow

    var delivery_date = $("#year").val()+'-'+$("#month").val()+'-'+$

    8天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信