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.

    评论

报告相同问题?