![](/img/trans.png)
[英]How do I close javascript popup box after validation is successful with php ajax call
[英]How do I print the successful statement in the if condition after getting values from an ajax call?
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").change(function(){
var p1 = $('#password1').val();
var p2 = $('#password2').val();
var p3 = $('#password3').val();
var p4 = $('#password4').val();
$.post('http://localhost../mycode.jsp',
{
pass1 : p1,
pass2 : p2,
pass3 : p3,
pass4 : p4,
},
function(data,status){
console.log(data)
alert("Status : "+ status);
});
});
});
</script>
</head>
<body>
<%
String pw1,pw2,pw3,pw4;
pw1 = "1";
pw2 = "2";
pw3 = "3";
pw4 = "4";
out.println("<div id='password' style=' display: block; position: absolute; left: 30%;'>");
out.println("<h1 style=' position: absolute; top: -120%; left: 18%; font-family: Titillium Web;'>PASSWORD</h1>");
out.println("<form method='POST'>");
out.println(" <input type='number' id='password1' maxlength='1' max='9' style=' width: 1%; padding: 12px 12px; margin: 8px 0px; border: none; border-bottom: 2px solid red;'>");
out.println(" <input type='number' id='password2' maxlength='1' max='9' style=' width: 1%; padding: 12px 12px; margin: 8px 0px; border: none; border-bottom: 2px solid red;'>");
out.println(" <input type='number' id='password3' maxlength='1' max='9' style=' width: 1%; padding: 12px 12px; margin: 8px 0px; border: none; border-bottom: 2px solid red;'>");
out.println(" <input type='number' id='password4' maxlength='1' max='9' style=' width: 1%; padding: 12px 12px; margin: 8px 0px; border: none; border-bottom: 2px solid red;'>");
out.println("</form>");
out.println("</div>");
String ele1 = request.getParameter("pass1");
String ele2 = request.getParameter("pass2");
String ele3 = request.getParameter("pass3");
String ele4 = request.getParameter("pass4");
if((pw1.equals(ele1)) && (pw2.equals(ele2)) &&(pw3.equals(ele3)) && (pw4.equals(ele4)))
out.println("Code Successful!!");
else
out.println("Code Failed.");
%>
</body>
</html>
這是我正在使用的基本代碼。 我想在用戶表單數據異步發送到服務器並且服務器執行任務之后執行操作。 如果條件值的值由用戶在運行時設置,我該如何更新那些值。
我想在用戶表單數據異步發送到服務器並且服務器執行任務之后執行操作。
假設我們堅持使用Jquery ajax, 那么響應異步請求而要做的任何事情都必須通過回調函數完成 。
換一種說法:
$.post('http://localhost../mycode.jsp',
// ... other arguments to ajax call
function(data,status){
// do stuff that requires waiting on async request HERE
});
多數民眾贊成在那唯一的地方,您知道請求已完成的任何狀態。
您可以將if
邏輯移到其中,或者另一個建議是將要執行的邏輯包裝到另一個較小的函數中。 然后從$.post
回調內部調用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.