且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在远程验证中将数据传递到服务器

更新时间:2023-02-02 17:23:50

引用OP :

如何将用户输入的数据发送到服务器?"

您不这样做,因为默认情况下已经发送了该邮件.

You don't, because that is already sent by default.

您的代码...

rules: { 
    "profile.userId": {  // <- this MUST be the 'name' attribute of the input
        required: true,
        minlength: 8,
        remote: {
            url: "/checkUniqueUserId",
            // dataType: "json",      // <- not needed, default
            type: "POST",
            // data: {userId : '???'} // <- not needed
        }
    }
}

如果只需要profile.userId字段的值,则无需执行任何操作.这就是默认情况下已经发送的确切数据.

If you just want the value of your profile.userId field, you don't need to do anything. That's the exact data already sent by default.

以PHP为例,可以通过$_POST数组作为$_POST['profile.userId']在服务器端进行简单访问. (这假定渲染的<input>元素包含name="profile.userId"属性,否则这些都不起作用.)

Using PHP as an example, it is simply accessed server-side with the $_POST array as $_POST['profile.userId']. (This assumes the rendered <input> element contains the name="profile.userId" attribute, otherwise none of this will work.)

仅当需要将其他数据发送到远程脚本时,才使用data选项 .例如,发送电子邮件地址和用户ID.

You would only use the data option if you need to send additional data to the remote script. Example, to send an email address along with the user id.

有关详细信息和示例,请参阅文档.