javascript - After ajax page allready reloads. -


I'm just searching Ajax to know it.

I try the following Javascript test code. / P>

  & lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.0 Transcription // N" & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Ajax demo & lt; / Title & gt; & Lt; Meta name = "" content = "" & gt; & Lt; Script type = "text / javascript" & gt; Function aa () {var xmlhttp; If (window.XMLHttpRequest) {// code for IE7 +, Firefox, Chrome, Opera, Safari xmlhttp = New XMLHttpRequest (); } Else {// code for IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); } XMLhttp.open ("GET", "getprod.php", false); Xmlhttp.send (); Document.getElementById ("myDiv") innerHTML = xmlhttp.responseText. } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form & gt; & Lt; Input type = "text" name = "txta" onchange = "aa ();" & Gt; & Lt; / Input & gt; & Lt; Br> & Lt; Div id = 'myDiv' style = "width: 400px; height: 300px; overflow-y: auto; range: # e 87517 1px solid" & gt; & Lt ;? Php $ mysqli = new mysqli ('localhost', 'root', 'password', 'ajax'); If ($ mysqli-> connect_errno) {die ("connect failed". $ Mysqli- & gt; connect_uper); } $ Mysqli- & gt; Set_charset ("utf8"); {$ Result = $ mysqli-> Query ("Select ID, name from test";) {while ($ row = $ result-> fetch_assoc ()) {echo $ row ['id'], "-", $ line ['name '], "& Lt; br & gt;"; } // while} // if $ result-> Close (); $ Mysqli- & gt; near (); ? & Gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

and some line for "getprod.php"

  & lt ;? Php echo "123"; ? & Gt;  

When I change values ​​in the textbox, Ajax gives me the desired string "123" and puts it in the div, but after a few seconds, div is again filled with the results of MySQL He is not desired

1) What is wrong with my code? (The goal is: When I change the value in the textbox, only returns strings from ajax - "123" should be permanently visible in the divi container.) 2) The textbox change event occurs when it loses focus or How do I change the event without this action when I press ENTER on the keyboard?

Thanks in advance.

change onkeypress or oninput Events for


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -