weixin_33736048 2015-10-31 13:54 采纳率: 0%
浏览 23

Ajax无法显示哈希符号

i have this code of HTML

<textarea cols="120" rows="4" name="editor" id="editor" onkeyup="sendData()"></textarea>
<span id="container" name="container"></span>

and this one in JS

function sendData(){
var hc = document.getElementById('editor').value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("container").innerHTML = xmlhttp.responseText;
    }
}
xmlhttp.open("GET", "w.php?h=" + hc, true);
xmlhttp.send();
}

also this one in w.php

<?php
$h = $_REQUEST['h'];
echo $h;
?>

when i use this code it's work very fine but there is a problem with tow letters first one "#" and second one "&" so how can i fix this problem :) thank you

  • 写回答

1条回答 默认 最新

  • weixin_33686714 2015-10-31 13:57
    关注

    You have to encode your data for a URI. Simply use

    encodeURIComponent(/* The data to encode here. */)
    

    before creating your request URL.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭