我有一个使用 Ajax 的 Drupal 网络应用; Ajax 函数有时需要将字符串作为参数传递给 Drupal 函数,如
$.ajax({url: "index.php?q=get_value/"+encodeURIComponent(value),
当值包含斜杠时,Drupal 函数无法将其识别为
function get_value($value) {
print urldecode($value);
例如,如果传递的字符串是 ABC/123 ,get_value 只打印 ABC
我如何解决传递斜杠并从 PHP/Drupal 获取整个字符串的问题?
最佳答案
使用 %2f
而不是 /
作为:
$.ajax({url: "index.php?q=get_value" + "%2f" + encodeURIComponent(value),
[ reference ], 见 2.2 节
或者,一个更具可读性的替代方案:
$.ajax({url: "index.php?q=" + encodeURIComponent("get_value/"+value),
关于javascript - 从 JS 到 Drupal 的 URL 编码字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10637181/