Grails的:页面将不会重定向后完成Ajax调用重定向、页面、Grails、Ajax

由网友(祭心)分享简介:这是我的ajax调用:<身体的onload =$ {remoteFunction(控制器:'accountManagement,动作:createAccount,PARAMS:[facebookUID:params.facebookUID,性别:params.gender,姓:params.firstName,名...

这是我的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.

阅读全文

相关推荐

最新文章