Grails的:页面将不会重定向后完成Ajax调用 [英] Grails: Page won't redirect after completed Ajax call

查看:150
本文介绍了Grails的:页面将不会重定向后完成Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ajax调用:<身体的onload =$ {remoteFunction(控制器:'accountManagement,动作:createAccount,         PARAMS:[facebookUID:params.facebookUID,性别:params.gender,姓:params.firstName,名字:params.lastName])}>

This is my ajax call: <body onload = "${remoteFunction(controller:'accountManagement', action:'createAccount', params:[facebookUID: params.facebookUID, gender: params.gender, firstName: params.firstName, lastName: params.lastName])}">

在我的控制器我在最后一个重定向指令:

In my controller I have a redirect instruction at the end:

def createAccount = {

    if(user.save(flush:true) == null){
        ... 
    }
    else{
        ....

        for(int i = 0; i < categories.length; i++){
            ...
        }

        println "save to database: successful"

    }

    // Redirect to index action of person controller.
    redirect(controller:'user', action: 'authenticate');


}
`

它不重定向。相反,它保持不变装载页上,它开始于

It does not redirect. Instead, it stays on the same loading page that it started on.

推荐答案

如果一个AJAX调用返回重定向浏览器将不会重定向。如果你想一个AJAX调用后向用户发送到一个新的页面,你需要做自己的Javascript。例如:

Browsers won't redirect if an AJAX call returns a redirect. If you want to send the user to a new page after an AJAX call, you'll need to do so yourself in Javascript. Example:

def url = createLink(controller: 'user', action: 'authenticate')
render(contentType: 'text/html', text: "<script>window.location.href='$url'</script>")

确保Ajax响应得到由浏览器中呈现。随着Grails的 remoteFunction 标签应指定与更新更新元素属性。

Ensure the AJAX response gets rendered by the browser. With the grails remoteFunction tag you should specify an element to update with the update attribute.

这篇关于Grails的:页面将不会重定向后完成Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆