简体   繁体   中英

ajax can't display hash sign

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

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

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

before creating your request URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM