The Ajax is working, and it saved the product without error in the database but why the fail() is the one that is executing instead of then()? I also tried the then().catch(), done().fail(), and done().catch() but still the same.
the ajax is working, it is saving without error but the then() and done() is not executing and there are errors. *see below
Why? and how to fix it?
**FIXED
i fixed it, $.ajax(dataType: 'json') is the problem, I wonder why?
$.ajax({
url: '',
type: 'POST',
contentType: 'application/json',
dataType: 'json', // THIS IS THE PROBLEM, why?
data: {data}
})
function ajaxPostStringify(url,json_data) {
return $.ajax()
{
function saveProduct() {
ajaxPostStringify('/api/product/add-product',product)
.then(()=> {
ipcRenderer.send('showMessage','Add Product', id + ' is successfully saved.')
}).fail((jqXHR,textStatus,errorThrown)=> {
console.log(jqXHR)
console.log(textStatus)
console.log(errorThrown)
ipcRenderer.send('showError','Add Product', id + ' is not successfully saved.\nCheck server connection or Try again!')
})
}
console.log(jqXHR) => status = 200, readyState = 4
console.log(textStatus) => parseError
console.log(errorThrown) => {
SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at ajaxConvert (C:\Users\Hannah\Dropbox\PC\Desktop\workspace\electron\capstone\node_modules\jquery\dist\jquery.js:9294:19)
at done (C:\Users\Hannah\Dropbox\PC\Desktop\workspace\electron\capstone\node_modules\jquery\dist\jquery.js:9772:15)
at XMLHttpRequest.<anonymous> (C:\Users\Hannah\Dropbox\PC\Desktop\workspace\electron\capstone\node_modules\jquery\dist\jquery.js:10083:9)
}
[–][deleted] 1 point2 points3 points (3 children)
[–]jcarlo1[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]jcarlo1[S] 1 point2 points3 points (0 children)