I have a script where I open a jQuery Dialog Box with a form. I send the values of the form via ajax to a php script. The php script save the value in a mysql database.
Everything work fine. But:
In the case, that something is wrong with the insert of mysql I will give a information back to the user. But not only "is wrong". I want give for example back "Already exists", "Wrong parameters" and so on.
How can give information back from the php script to tha jQuery Dialog Box?
My script looks like this:
function openmodal() {
var $dialogContent = $("#create_mieter"),
mieterID = $("#mieterID"),
snID = $( "#snID" ),
mietwechsel = $("#datepicker"),
zahlart = $("#zahlart");
$dialogContent.dialog({
height: "auto",
width: 500,
modal: true,
resizable: false,
title: "Neues Mietverhältnis anlegen",
close: function() {},
buttons: {
Sichern : function() {
$.ajax({
type: "POST",
url: "wohnungen_bearbeiten_mieter_sichern.php?act=create",
data: "mieterID=" + mieterID.val() + "&snID=" + snID.val() + "&mietwechsel=" + mietwechsel.val() + "&zahlart=" + zahlart.val(),
success: function(response) {
alert("Show Success");
},
error: function() {
alert("Sorry something went wrong");
}
});
$( this ).dialog( "close" );
},
Abbrechen : function() { $( this ).dialog( "close" ); }
}
}).show();
$("#ui-datepicker-div").css("z-index", "99999");
json stringto be sent back to the server in thesuccess: function(response). Then you can doif(response.error){alert(response.error)}else{$(this).dialog('close')}.