Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
XML
<script src="jquery.min.js" type="text/javascript"></script>
        <script>

    $(document).ready(function() {
    var val1 = "";
    var val2 = "";

    $('input[name="pet"],input[name="danger"]').change(function() {
        val1 = $('input[name="pet"]:checked').val();
        val2 = $('input[name="danger"]:checked').val();
        alert(val1 + " : " + val2);
        $.post('ajax-example.php',{'pet' : val1}, function(){
 });

        });

});

here i am getting the values but to pass those val1,val2 values to my ajax-example.php
Posted

1 solution

I see you already use jQuery.

I'd suggest you try the jquery.ajax function, is more versatile than jquery.post, and maybe easier to understand.

It's also more configurable than jQuery.post, in the sense that you can use the same syntax for both GET or POST requests

JavaScript
$.ajax({
	type : 'POST',
	url : 'ajax-example.php',
	data: {
		pet: val1,
		pet2: val2
	},
	success : function(data) {
		//Do your thing when the call is successful
	},
	error: function(data) {
		//Treat error when they occur
	}
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900