javascript - xmlhttp.open does not seem to do anything in MVC structure -


i'm trying add auto-complete function text field. used work, switched mvc structure , can't work.

php/html:

echo '<br><br>add member:<br>'     . '<form method="post"><input type="text" name="username" oninput="findusers(this.value)" list="livesearch">'     . '<datalist id="livesearch"></datalist>'     . '<input type="submit" value="add">'     . '</form>'; 

javascript:

<script> function findusers(str) {     if (str == "") {         document.getelementbyid("livesearch").innerhtml = "no suggestions";         xmlhttp.send();     } else {         if (window.xmlhttprequest) {                 // code ie7+, firefox, chrome, opera, safari                 xmlhttp = new xmlhttprequest();         } else {                 // code ie6, ie5                 xmlhttp = new activexobject("microsoft.xmlhttp");         }         xmlhttp.onreadystatechange = function() {                 if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {                         document.getelementbyid("livesearch").innerhtml = xmlhttp.responsetext;                 }         };         xmlhttp.open("get","/user/search/?q="+str,true);         xmlhttp.send();     } } </script> 

/user/search opens function called search in class user in usercontroller.php file

class usercontroller extends controller { public function search()     {         $response = "hello";         echo $response;     } } 

so should put "hello" message in livesearch datalist. reason nothing happening. if replace xmlhttp.open window.open, page load , shows hello message. not want.


figured out exact problem:

my xmlhttp.responsetext returning header of website, loaded in mvc structure.

how work around this? option edit string , last part in javascript? or there better solutions?

used javascript grab last part of string (so without header) it's supposed now, feels pretty "dirty" solution.

also had add <option value=""> tag, in code, not in testcode.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -