繁体   English   中英

如何检查数据是否在Ajax中传递

[英]How to check if data is passed in ajax

我有以下要求才能获得注册表格以发布数据。 但是我无法测试它,任何人都可以帮忙。 我想看看是否正在传递数据? 我既有jquery cdn又有jquery-validate。

我有矮人

jQuery的:

// Code goes here

$(function() {

    /* Registration form for the website */
    /* validation */
    $("#register-form").validate({
        rules: {
            firstName: {
                required: true
            },
            lastName: {
                required: true
            },
            userName: {
                required: true,
                minlength: 4
            },
            email: {
                required: true,
                email: true
            },
            password: {
                required: true,
                minlength: 8,
                maxlength: 15
            },
            cpassword: {
                required: true,
                equalTo: '#password'
            },
        },
        messages: {
            userName: "please enter a valid user name",
            password: {
                required: "please provide a password",
                minlength: "password at least have 8 characters"
            },
            email: "please enter a valid email address",
            cpassword: {
                required: "please retype your password",
                equalTo: "password doesn't match !"
            }
        },
        submitHandler: submitForm
    });
    /* validation */

    /* form submit */
    function submitForm() {
        var data = $("#register-form").serialize();
        // var data={
        //  firstName: $('#firstName').val(),
        // }

        $.ajax({

            url: 'http://localhost:8000?userName=&password=&firstName=&lastName=&email=',
            type: 'POST',
            data: data,

            beforeSend: function() {
                $("#error").fadeOut();
                $("#btn-submit").html('<span class="glyphicon glyphicon-transfer"></span> &nbsp; sending ...');
            },

            success: function(data) {
                if (data === 0) {

                    $("#error").fadeIn(1000, function() {


                        $("#error").html('<div class="alert alert-danger"> <span class="glyphicon glyphicon-info-sign"></span> &nbsp; Sorry email already taken !</div>');

                        $("#btn-submit").html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Create Account');

                    });

                } else if (data == 1) {

                    $("#btn-submit").html('<img src="btn-ajax-loader.gif" /> &nbsp; Signing Up ...');

                } else {

                    $("#error").fadeIn(1000, function() {

                        $("#error").html('<div class="alert alert-danger"><span class="glyphicon glyphicon-info-sign"></span> &nbsp; ' + data + ' !</div>');

                        $("#btn-submit").html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Create Account');

                    });

                }
            }
        });
        return false;
    }
});

网络标签

如果您检查浏览器,请转到“网络”标签。 在其中选择XHR选项卡。 这些都是进行的AJAX调用。 在这里,您可以查看状态代码,持续时间等。

注意:这是Chrome浏览器的屏幕截图

您可以使用console.log(data)查看什么数据变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM