Can Ajax tell you if a mysql query was successful?

Good day

I need to check if the mysql query was successful, not if the AJAX call was successful.

Basically how do I know if the data was added into the database (with php I can just call if (!$result){echo $db->error;exit();} but I need to get this via the Ajax call.

How may I achieve this?

My code:

    $('body').on('submit', '#add_payment_form', function(){
    		console.log($( this ).serialize()+'&submit=true');
    		$.ajax({
    			url: "payments.inc.php",
    			method: "POST",
    			data: $( this ).serialize()+'&submit=true',
    			success: function (data, html, response) {
    				console.log(data);
    				$("#add_payment_form").trigger( "reset" ); /*Reset form fields to empty if successful*/
    			}
    		});
    		event.preventDefault();
    	});

My current solution (very unstable and prone to errors):

$('body').on('submit', '#add_payment_form', function(){
		console.log($( this ).serialize()+'&submit=true');
		$.ajax({
			url: "payments.inc.php",
			method: "POST",
			data: $( this ).serialize()+'&submit=true',
			success: function (data, html, response) {
				console.log(data);
				if (data.indexOf("success") > -1) { /*Check if the returned data has the word success in it*/
					$("#add_payment_form").trigger( "reset" );
				}
			}
		});
		event.preventDefault();
	});
Sponsor our Newsletter | Privacy Policy | Terms of Service