在jQuery中转义斜杠以在AJAX请求中传递路径

Dyc*_*cey 7 jquery escaping

我有斜线问题!我有一些jQuery用于处理页面上的通用对话框.在某些情况下,字段是通过/分隔路径...

var fieldValues = [];
// pull values from all the fields belonging to the dialog...
$.each($(this).find('input, textarea, select'), function(n,field) {
  // escape the path fields
  var value = escape($(field).val().replace(/\//g,'__slash__'));
  //alert ($(field).attr('id')+'='+value);
  if(id != '' && value != '') {
    fieldValues.push(id+'='+value);
  }
});
Run Code Online (Sandbox Code Playgroud)

这段代码有效,但是当我到达php结束时,我手动剥离__slash__.是否有一些编码功能,我错过了让我放弃看起来笨拙的替换?

And*_*all 5

您可以使用Javascript的内置功能encodeURIComponent(),然后PHP rawurldecode()应该在收到PHP后对其进行解码.