简体   繁体   中英

XMLHttpRequest Breaking HTML code

This appears to be an issue with grabbing this info, the following is parsed on my *.php file:

<form method="POST" action="portalofinfiniteawesome.php">
<input type="hidden" name="account" value="' . $username . '" />
<button type="submit" class="btn btn-warning" value="wrong">These are wrong</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Nevermind</button>
<button type="submit" class="btn btn-primary" value="right">View Buddies</button>
</form>

However when I grab this with:

    function showHint(str)
    {
    if (str.length<4)
      {
      document.getElementById("results").innerHTML="";
      return;
      }
    var xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("results").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","searcher.php?q="+str,true);
    xmlhttp.send();
    }

Onto my new page, it is rendered as:

<form method="POST" action="portalofinfiniteawesome.php"></form>
<input type="hidden" name="account" value="' . $username . '" />
<button type="submit" class="btn btn-warning" value="wrong">These are wrong</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Nevermind</button>
<button type="submit" class="btn btn-primary" value="right">View Buddies</button>

I just need this to work, I do not care if I need to use jquery or anything in addition, just hoping to resolve this issue and would appreciate getting an answer or at least being put in the right direction.

All help is appreciated, thanks in advance.

Problem persists on IE, Firefox, Chrome

Try replacing:

<input type="hidden" name="account" value="' . $username . '" />

With this:

<input type="hidden" name="account" value="' . $username . '" ></input>

Firefox can do that.

My one pence:

Unless the form block is inside a PHP string, then the respective line should be:

<input type="hidden" name="account" value="<?php echo $username ?>" />

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