Validation - Stop ajax if false or proceed is true.

Alex Lord
Alex Lord used Ask the Experts™
on
bootbox.confirm("Are you sure you wish to change this field?", function(result)
                    { 

                         

                    });
             
             
                        $.ajax({
                            type: "POST",
                            url: 'set-field-value.php',
                            data: formData,
                            processData: false,
                            contentType: false,
                            dataType: "json" 
                        }).success(function(response){
                            console.log(response);
                   

                        }).error(function (response) {

Open in new window



So above is start of a function i have which will update fields but i am doing some valuation. the bootbox brings up a dialog with message and two buttons which sets a result either true or false. im wondering how do i within that dialog function proceed to ajax is true and stop function and not reach ajax if false.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
The callback function receives a boolean, so just check that and bug out if it's false:

bootbox.confirm("Are you sure you wish to change this field?", function(result) { 

	if ( ! result ) return;
	
	$.ajax({
		type: "POST",
		url: 'set-field-value.php',
		data: formData,
		processData: false,
		contentType: false,
		dataType: "json" 
	}).success(function(response){
		console.log(response);
	}).error(function (response) {
		
	});

});

Open in new window

Author

Commented:
ty chris :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial