Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jQuery的alert函数之前,用户值是准确的,但saveorupdate函数在db表中保留空值_Javascript_Jquery_Ajax_Hibernate_Spring Mvc - Fatal编程技术网

Javascript 在jQuery的alert函数之前,用户值是准确的,但saveorupdate函数在db表中保留空值

Javascript 在jQuery的alert函数之前,用户值是准确的,但saveorupdate函数在db表中保留空值,javascript,jquery,ajax,hibernate,spring-mvc,Javascript,Jquery,Ajax,Hibernate,Spring Mvc,在jQuery的alert函数中,这些值会作为用户输入的内容发出警报,但在数据库表中,这些值会以null的形式持久化。谁能告诉我我做错了什么或者是什么导致了这一切 有人能告诉我,在JavaScriptelse语句中绑定jQuery是错误的吗?如果是,当我警告值时,它应该将null作为值,但jQuery函数会准确地警告用户输入,还是AJAX,传递null值,或者控制器类中存在需要修改的问题。谢谢 用于验证的JavaScript函数和用于绑定和发送数据的jQuery: function valida

在jQuery的alert函数中,这些值会作为用户输入的内容发出警报,但在数据库表中,这些值会以
null
的形式持久化。谁能告诉我我做错了什么或者是什么导致了这一切

有人能告诉我,在JavaScript
else
语句中绑定jQuery是错误的吗?如果是,当我警告值时,它应该将
null
作为值,但jQuery函数会准确地警告用户输入,还是AJAX,传递
null
值,或者控制器类中存在需要修改的问题。谢谢

用于验证的JavaScript函数和用于绑定和发送数据的jQuery:

function validate2() {
  var R_name = document.getElementById("R_name").value;
  var R_email = document.getElementById("R_email").value;
  var R_number = document.getElementById("R_number").value;
  var R_pass = document.getElementById("R_pass").value;
  var R_password = document.getElementById("Rc_pass").value;
  var re = /[0-9]/;
  var atposition = R_email.indexOf("@");
  var dotposition = R_email.lastIndexOf(".");

  if (R_name == "" || R_email == "" || R_number == "" || R_pass == "" || R_password == "") {
    alert("please fill the form");
  } else if (R_name.length < 3) {
    alert("name is too short");
  } else if (atposition < 1 || (dotposition - atposition < 2))
  /* if user gives email which starts with @ or if there is no words inbetween (@) and (.)  */
  {
    alert("Please enter correct email ID");
  } else if (R_number.length < 6) {
    alert("number is too short");
  } else if (R_pass.length < 8) {
    alert("password should have minimum 8 characters");
  } else if (!re.test(R_pass)) {
    alert("Error: password must contain at least one number (0-9)!");
  } else if (R_password !== R_pass) {
    alert("passwords do not match");
  } else {
    $(function() { // this function will load on submit//
      alert(R_name);
      alert(R_email);
      alert(R_number);
      alert(R_pass);
      alert(R_password);
      $.ajax({ // defining the below function as ajax responsive//
        url: 'saveOrUpdate', // the function that process the  mapped url name and matching type is going to receive the data//
        type: 'POST',
        data: {
          R_name,
          R_number,
          R_email,
          R_pass
        }, // function to get the value from jsp page and send it to mapped class function//
        success: function(response) { // if the backend process is success then the function will run by getting the response as its parameter//
          alert(response.message);
        }
      });
    });
  }
}
HTML:


  • 我接受条款和条件

大致检查代码后,我认为以下行包含错误:

data:{R_name,R_number,R_email,R_pass}
当您将
数据
传递给
servlet
时,servlet将以
对象
格式读取数据,因此您需要将键分配给
参数
,并使用
请求.getParameter('keyName')
读取它们。因此,请尝试使用以下方法:

data:{name:R_name,number:R_number,email:R_email,pass:R_pass}

非常感谢您阅读代码,我尝试了您的建议,但值仍然保持为null,我非常感谢你的建议,虽然你是正确的,但我忘了包括密钥,先生,还有一个错误是我有一个名为user_number的输入,类型为integer,我的映射只能接受sting和object类型,所以我将user_number改为string类型,并确保我的pojo中的变量名和键值相同,并且有效先生非常感谢,先生,你太棒了!!非常感谢您对我的帮助我再也无法表达我的感激之情了非常感谢先生。
data:{R_name,R_number,R_email,R_pass}
data:{name:R_name,number:R_number,email:R_email,pass:R_pass}