我有一个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
更多推荐
发布评论