I am developing an application in asp.net using mvc. I try to send an image's bytes to the controller through a jQuery ajax request and I am encountering a problem.
When I leave a field empty and click the submit button, the message will append "please enter this field". So, the ajax request should be stopped but when I fill in this input field and click the button, the ajax request is called two times and the image is also saved in the database two times.
How can I stop this duplication?
if (Productname == "") {
alert("Please Enter Product Name");
return;
}
else if (Ratei == "") {
alert("Please Enter Product Price");
return;
}
else if (URLi == "") {
alert("Please Enter Ebay Url");
return;
}
else {
var postdata = { ProductName: Productname, ModelID: ModelID, Rate: Ratei, Discount: Discounti, Condition: Conditioni, Url: URLi, Desc: Descriptioni, shDesc: shDescriptioni }
var ProductId = 0;
$.ajax({
type: "POST",
// url: "/EcommerceAdmin/Admin/addProduct",
url: "/Admin/addProduct",
data: postdata,
success: function (data) {
ProductId = data.id;enter code here
}
});
}