gpt4 book ai didi

javascript - jQuery 试图处理 ajax 失败和成功不起作用

转载 作者:行者123 更新时间:2023-11-29 10:37:00 24 4
gpt4 key购买 nike

我有一个有效的 jQuery ajax 调用,但我想检查请求的结果,所以我添加了

success: function(data) {
if(data.status == 'success'){
alert("Thank you for subscribing!");
}else if(data.status == 'error'){
alert("Error on query!");
}
}

但这不起作用,甚至让我的整个功能停止工作。所以这是整个功能,有人能告诉我哪里做错了吗`

   function addGoal()  {

var description = $('.description').val();
var measure = $('.measure').val();

if( description.trim() && measure.trim() ){
if(window.confirm("Are you sure? You can't edit or remove goal(s) you have added here.")==true) {

$.ajax({
url: '${g.createLink( controller:'review', action:'saveGoal', params:[id: params.id] )}',
data: {
"description": description,
"measure": measure
},

success: function(data) {
if(data.status == 'success'){
alert("Thank you for subscribing!");
}else if(data.status == 'error'){
alert("Error on query!");
}
}
type: 'POST'
});
}
}else {
showErrorMessage("Description and Measure fields cant be empty");
}
}`

当我删除成功时,它会按我预期的那样工作。如果重要的话我正在使用 grails

最佳答案

语法错误,缺少逗号

   function addGoal()  {

var description = $('.description').val();
var measure = $('.measure').val();

if( description.trim() && measure.trim() ){
if(window.confirm("Are you sure? You can't edit or remove goal(s) you have added here.")==true) {

$.ajax({
url: '${g.createLink( controller:'review', dataType: "json", action:'saveGoal', params:[id: params.id] )}',
data: {
"description": description,
"measure": measure
},

success: function(data) {
if(data.status == 'success'){
alert("Thank you for subscribing!");
}else if(data.status == 'error'){
alert("Error on query!");
}
},
type: 'POST'
});
}
}else {
showErrorMessage("Description and Measure fields cant be empty");
}
}`

这将解决问题

关于javascript - jQuery 试图处理 ajax 失败和成功不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34946266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com