Ajax和Grails

编程入门 行业动态 更新时间:2024-10-10 11:25:05
Ajax和Grails - 如何在Ajax的成功中使用模型中的参数?(Ajax & Grails - how to use the params from the model in the success of the Ajax?)

我有一个Ajax调用控制器中的动作。

控制器渲染:

render template:"changePassword", model:[user: user, passwordError: passwordError]

passwordError是boolean。

如果passwordError为true,我必须在js.file中执行函数。

如何检查成功的Ajax passwordError的值?

Ajax的代码:

$.ajax({ url: changePassword, type: "post", data: { password: $('#password').val(), npassword: $('#npassword').val() }, success: function(data,textStatus){ $('#changePassSuceess').modal() } });

I have an Ajax which call to an action in a controler.

The controller render:

render template:"changePassword", model:[user: user, passwordError: passwordError]

The passwordError is boolean.

In case the passwordError is true I have to perform function in the js.file.

How can I check in the success's Ajax the value of the passwordError?

The code of the Ajax:

$.ajax({ url: changePassword, type: "post", data: { password: $('#password').val(), npassword: $('#npassword').val() }, success: function(data,textStatus){ $('#changePassSuceess').modal() } });

最满意答案

如果你不需要渲染模板,你可以返回一个json作为@Eylen提到,然后从json访问该标志。 如果你必须渲染一个模板,那么你可以在模板中有一个隐藏字段,其值设置为标志passwordError,然后你可以在你的javascript代码中从这个隐藏字段中获取flag的值

有关如何在jquery ajax响应html中查找隐藏元素,请参阅此问题

If you dont need to render a template, you can return a json as @Eylen mentioned and then access the flag from json. If you must render a template then you can have a hidden field in your template with value set to the flag passwordError and then you can get the value of flag from this hidden field in your javascript code

See this question for how to find hidden element in jquery ajax response html

更多推荐

本文发布于:2023-08-03 09:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Ajax   Grails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!