Php 在从数据库jquery中获取消息说已经存在后中止jquery pos

Php 在从数据库jquery中获取消息说已经存在后中止jquery pos,php,jquery,ajax,Php,Jquery,Ajax,当我收到消息说数据库中已经存在数据后,如何中止jquery进程?这是因为我需要检查id,如果不存在,则使用$.post(“process.php”)将其插入数据库,这可能吗 $.post("checkdata.php", { //check from database if id already exist id1: id //data to be check from database }, function(data) { if

当我收到消息说数据库中已经存在数据后,如何中止jquery进程?这是因为我需要检查id,如果不存在,则使用$.post(“process.php”)将其插入数据库,这可能吗

$.post("checkdata.php", {        //check from database if id already exist
id1: id                          //data to be check from database
}, function(data) {
if (data == 'CUSTOMER ID ALREADY EXIST!') { // if return this terminated the process
$("#output").html("CUSTOMER ID ALREADY EXIST!"); //showing error to client
$("form")[0].reset();            //reset the form
e.abort();                       //aborting the process
}

if (code == '' || (code.length) < 8) {
$("#output").html("CUSTOMER CODE SHOULD HAVE ATLEAST 8 CHARACTER");
$("#code").addClass('error');
$("#code").focus();
}

$.post("process.php", {
id1: id,
code1: code
}, function(data) {
if (data == 'Information added successfully!') {
$("#output").html("Information added successfully!");
$("form")[0].reset();
}
$.post(“checkdata.php”,{//如果id已经存在,则从数据库中检查
id1:id//要从数据库检查的数据
},函数(数据){
如果(数据==“客户ID已存在!”){//如果返回此消息,则终止进程
$(“#输出”).html(“客户ID已存在!”;//向客户显示错误
$(“表单”)[0].reset();//重置表单
e、 abort();//正在中止进程
}
如果(代码=“”| |(代码长度)<8){
$(“#输出”).html(“客户代码应至少包含8个字符”);
$(“#代码”).addClass('error');
$(“#代码”).focus();
}
$.post(“process.php”{
id1:id,
代码1:代码
},函数(数据){
如果(数据=='已成功添加信息!'){
$(“#输出”).html(“信息添加成功!”);
$(“表单”)[0]。重置();
}

我认为您要做的是重新构造代码,以便首先在浏览器中进行签入(验证表单)。然后,如果表单有效,您可以向服务器发出请求(
checkdata.php
)。收到响应后,您可以决定是否继续向服务器发出另一个请求(
process.php


我想要的基本上是这样的,检查id是否从服务器端复制->传递所有文本输入(JS)->向服务器添加数据,我不想要他们(客户)传递所有客户端,但当到达服务器端时,他们的请求被拒绝,因为id重复,我在这里放置的js仅用于2个textbox,使其简短,但真实的一个有10多个要让您知道,id也来自textbox,所有textbox都是必需的,并且从您键入的第二个代码开始,您让客户传递所有请求客户端需要检查是否重复,在插入到数据库之后,让我们在客户通过所有10+文本框(JS)之后插入时说它失败,他/她可能会跑掉。这是一个ajax请求,您可以在id字段失去焦点时立即向服务器发出请求。对于用户,他们可能会用tab键离开或单击另一个字段。然后,当他们填写完第二个字段时,您可以显示一条消息,说明id是重复的。这样,就不会打断用户直到它必须流动。
// Validate the form
if (code == '' || (code.length) < 8) {
  $("#output").html("CUSTOMER CODE SHOULD HAVE ATLEAST 8 CHARACTER");
  $("#code").addClass('error');
  $("#code").focus();
}
else {
  // The form is valid

  $.post("checkdata.php", {
    id1: id
  }, function(data) {

    if (data == 'CUSTOMER ID ALREADY EXIST!') {
      $("#output").html("CUSTOMER ID ALREADY EXIST!");
      $("form")[0].reset();
      return; // Don't continue with the following lines;
    }

    $.post("process.php", {
      id1: id,
      code1: code
    }, function(data) {
      if (data == 'Information added successfully!') {
        $("#output").html("Information added successfully!");
        $("form")[0].reset();
      }
    });

  });

}
// Client.js
if (code == '' || (code.length) < 8) {
  $("#output").html("CUSTOMER CODE SHOULD HAVE ATLEAST 8 CHARACTER");
  $("#code").addClass('error');
  $("#code").focus();
}
else {

  // The form is valid

  $.post("process.php", {
    id1: id,
    code1: code
  }, function(data) {
    if (data == 'duplicate customer') {
      $("#output").html("This is a duplicate customer");
      $("form")[0].reset();
    }
    else if (data = 'successful') {
      $("#output").html("Customer successfully added");
      $("form")[0].reset();
    }
    else {
      $("#output").html("Unknown error");
      // $("form")[0].reset();
    }
  });

}