php - $_GET the value of (&) with AJAX -
i have 3 codes first 1 html:
<html> <head> <script type = "text/javascript" src = "ajax.js"></script> </head> <body> <form method = "get" > <input type = "text" id ="a" ><br> <input type = "text" id = "b"><br> <input type = "button" value ="click" onclick = "process()"><br> <textarea id = "underbutton" ></textarea><br> </form> <body> </html> now javascript (ajax) :
function process() { if(xmlhttp.readystate==0 || xmlhttp.readystate==4){ = document.getelementbyid("a").value; b = document.getelementbyid("b").value; xmlhttp.onreadystatechange = handleserverresponse; xmlhttp.open("get","file.php?a="+a+"&b="+b,true); xmlhttp.send(); } } function handleserverresponse (){ if(xmlhttp.readystate==4 && xmlhttp.status==200) { response = xmlhttp.responsetext; document.getelementbyid("underbutton").innerhtml = response ; } } now php file :
<?php echo $_get['a'].'<br>'; echo $_get['b'].'<br>'; ?> everything working problem when type in first texbox (a) word hello , second (b) code & , click button ; must print out hello&.
prints hello!!
hello without &.
i noted sending php file : file.php?a=hello&b=&.
last & must %26
so print out & must send : file.php?a=hello&b=%26.
how can fix ??
change in javascript:
- = document.getelementbyid("a").value; - b = document.getelementbyid("b").value; + = encodeuricomponent(document.getelementbyid("a").value); + b = encodeuricomponent(document.getelementbyid("b").value);
Comments
Post a Comment