hunt hunt - 7 months ago 43
Ajax Question

How to prompt error if data is not inserted?

type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: "vos001_view.aspx/SaveRecordVS",
data: "{'id':'" + id + "','certType':'" + certType + "', 'Certificate':'" + Certificate + "', 'Place':'" + Place + "', 'Date':'" + Date + "', 'Effective':'" + Effective + "', 'Expiry':'" + Expiry + "', 'Attachment':'" + Attachment + "', 'Remarks':'" + Remarks + "'}",
success: function (test) {

alert('Vessel Certificate Insert Successful');

Error: function (xhr, ajaxOptions, thrownError) {
Ext.Msg.alert(xhr.responseText, thrownError);

i'm using ajax, even when the id is duplicate it still prompt insert successful.
How to prompt error if there is error and does not allow it to enter to database?
Thank you.


I would console.log your ajax response in the success function so if there is an error you would see it in your console in your browser:

success: function(result) {

Also I would comment out the page reload like so //location.reload(); while you are testing so you can still read the errors in your console.

As far as stopping it from not allowing it to "enter to database" that would all be done on the server side.