1

how i can add this variables to the code above? i need to pass these two variables. I tried but the code doesn't work as i expect (alerts doesn't working with the alterations).

        name: $('#name').val(),
        email: $('#email').val()


<script type="text/javascript">
    jQuery(document).ready(function() {
        $.ajax("valid.php", {
            type: "POST",
            dataType: "json",
            name: $('#name').val(), //here??
            email: $('#email').val() //here??
            success: function(step) {

                if (step.first) {
                    alert("fdsgdfg");
                }
                if (step.second) {
                    alert("dfgdfg");
                }

            }
        });
    });
</script>

thanks!

2 Answers 2

5

Add another part to your ajax call called "data".

<script type="text/javascript">
jQuery(document).ready(function() {
    $.ajax("valid.php", {
        type: "POST",
        dataType: "json",
        data: { name: $('#name').val(), email: $('#email').val() },
        success: function(step) {

            if (step.first) {
                alert("fdsgdfg");
            }
            if (step.second) {
                alert("dfgdfg");
            }

        }
    });
});

Alternatively:

$.ajax({
    type: "POST",
    url: "some.php",
    data: "name=John&location=Boston",
    success: function(msg){
        alert( "Data Saved: " + msg );
    }
});
Sign up to request clarification or add additional context in comments.

Comments

2

As stated in the jQuery documentation, you pass data with the request using the data option:

jQuery(document).ready(function() {
    $.ajax("valid.php", {
        type: "POST",
        dataType: "json",
        data: { name: $('#name').val(), email: $('#email').val() }, 
        success: function(step) {

            if (step.first) {
                alert("fdsgdfg");
            }
            if (step.second) {
                alert("dfgdfg");
            }

        }
    });
});

Comments

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.