Home > Article > Backend Development > Detailed explanation of ajax implementation of input prompt effect example
js can realize the page input prompt effect, and ajax can also do it. This article mainly introduces in detail the method of ajax to realize the input prompt effect. It has certain reference value. Interested friends can refer to it. I hope it can help. Everyone.
Website home page
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin:0px auto; padding:0px; } .l{ height:50px; width:198px; border-bottom:1px solid black; text-align: center; line-height:40px; vertical-align: middle; } </style> <script src="../wenjian/jquery-2.2.3.min.js"></script> </head> <body> <p style="height: 50px;width: 200px"><input type="text" id="name" style="width: 198px;height: 48px;"></p> <p id="list" style="height: 500px;width: 200px;border: 1px solid black"> <!--<p id="l">zhongguo</p>--> </p> </body> </html> <script> $("#name").keyup(function () { var n = $("#name").val(); if (n != ""){ $.ajax({ url:'ltchuli.php', data:{n:n}, type:'post', // dataType:'text', dataType:'json', success:function (data) { //text写法 // var s = data.split("|"); // var str = ""; // for (var i=0;i<s.length;i++) // { // str = str + "<p class='l'>" +s[i] +"</p>"; // } // $("#list").html(str); //json写法 for (var i in data){ $("#list").append("<p class='l'>" +data[i] +"</p>"); } } }); }else { $("#list").html(""); } }) </script>
Processing page
<?php /** * Created by fcc * User: Administrator * Date: 2017/10/30 * Time: 9:52 */ $n = $_POST['n']; require_once "../wenjian/DBDA.class.php"; $db = new DBDA(); $obj = "select region_name from region WHERE region_name LIKE '%{$n}%' "; $data = $db->Query($obj); //echo $data; echo json_encode($data);
Related recommendations:
jquery simulated title prompt effect
Practical JS form validation prompt effect_Form special effects
Based on jquery to achieve beautiful dynamic information prompt effect_jquery
The above is the detailed content of Detailed explanation of ajax implementation of input prompt effect example. For more information, please follow other related articles on the PHP Chinese website!