Advertisement
am_dot_com

CN 2022-05-20

May 20th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Search Client Example</title>
  6. <script>
  7. function ajaxPost(
  8. pUrl,
  9. pWhereToReply,
  10. pTheData
  11. ){
  12. var req = new XMLHttpRequest()
  13. if(req){
  14. req.open(
  15. "POST",
  16. pUrl,
  17. true
  18. )
  19.  
  20. req.mWhereToReply = pWhereToReply
  21. req.onreadystatechange = howToReact
  22. req.send(pTheData)
  23. }
  24. }//ajaxPost
  25.  
  26. function howToReact(){
  27. if (this.readyState===4 && this.status===200){
  28. this.mWhereToReply.innerHTML = this.responseText
  29. }
  30. else{
  31. this.mWhereToReply.innerHTML = this.readyState
  32. }
  33. }//howToReact
  34.  
  35. window.onload = boot
  36.  
  37. function boot(){
  38. /*
  39. var o = document.getElementById("idFeedback")
  40. var theData = new FormData()
  41. theData.append("q", "lee")
  42.  
  43. ajaxPost(
  44. "http://localhost:5002/search",
  45. o,
  46. theData
  47. )
  48.  
  49. */
  50. document.getElementById("idForm").onsubmit =
  51. produzPedido
  52. }//bot
  53.  
  54. function produzPedido(){
  55. var theData = new FormData(
  56. document.getElementById("idForm")
  57. )
  58. var oReqPost = ajaxPost(
  59. "http://localhost:5002/search",
  60. document.getElementById("idFeedback"),
  61. theData
  62. )
  63. return false
  64. }
  65. </script>
  66. </head>
  67. <body>
  68. <form
  69. id="idForm"
  70. method="post"
  71. action="http://localhost:5002/search"
  72. >
  73. <input type="text" name="q" value="senator" id="idQ">
  74. <input type="submit" value="fazer pedido">
  75. </form>
  76. <section id="idFeedback"></section>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement