0

I have the below requirement to get the registration form to post the data. But I am unable to test it, could anyone please help. I want to see whether the data is being passed or not? I have both jquery cdn and jquery-validate in place.

I have the plunker

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;
    }
});
5
  • 6
    Open up your console, go to the network tab, click the request that goes out and inspect what was sent. Commented Jan 20, 2017 at 15:20
  • 5
    Use the network tab of the console. It shows all requests the browser makes, along with the data in them and the response they receive Commented Jan 20, 2017 at 15:20
  • Like Rory said in Chrome or Firefox. Commented Jan 20, 2017 at 15:23
  • In developer tools on any browser, you can also open a Source tab and set breakpoints and step through your code nowadays. This isn't like the savagery of the early web... Commented Jan 20, 2017 at 15:25
  • Possible duplicate of How do I debug a jQuery Ajax request? Commented Jan 20, 2017 at 15:33

2 Answers 2

6

Network tab

If you inspect your browser, go onto the network tab. Select the XHR tab within there. Those are all AJAX calls being made. From here you can see the Status codes, duration, etc.

Note: this is a screenshot of the Chrome browser

Sign up to request clarification or add additional context in comments.

1 Comment

@Bob Glad it helped, If you click on the calls you can expand them and check the headers for further information as well
0

You can use console.log(data) to see what data variable is.

3 Comments

I would add JSON.stringify: console.log(JSON.stringify(data, null, 4))
Thank you all, I have marked the answer and also I see the data which is posted :) I really appreciate all your help. @Leo
Where should the console.log(data) be placed? Below Data:data?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.