Grails的jQuery的Ajax请求 - URL不工作 [英] Grails jQuery Ajax request - URL not working

查看:91
本文介绍了Grails的jQuery的Ajax请求 - URL不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜查了网,并在这里计算器,但我无法找到任何这提示...

I searched the net and also here at stackoverflow, but I couldn't find any hint on this...

我有一个Grails 2.1.1项目,我想打电话给从jQuery的一个控制器的功能与Ajax请求。到目前为止,我想出了这一点:

I've got a Grails 2.1.1 project and I want to call a Controller function from jQuery with an Ajax request. So far, I come up with this:

$.ajax({
    type: 'POST',
    url: "${createLink(controller:'userSearch',action:'ajaxFindUser')}",
    dataType: 'json',
    data: {
        lastname: $('#searchLastName').val(),
        firstname: $('#searchFirstName').val(),
        zipcode: $('#searchZipCode').val(),
        city: $('#searchCity').val()
    },
    success: function(data) {
        $('#searchSubContainerBody').html(data);

        $('#searchTable tr').draggable({
           cursor: 'move',
           helper: 'clone',
           scope: 'drag-guests',
            start: function(event, ui) {
              searchCloneTableRow.tr = this;
                searchCloneTableRow.helper = ui.helper;
                searchCloneTableRow.cells = new Array();
                $.each(this.cells, function(index, column) {
                    searchCloneTableRow.cells.push(column.innerText);
                });
            },
            connectWith: '#searchDetailContainerDropArea'
        });

        $('searchTable').dataTable({
            'bJQueryUI':true
        });

    },
    error: function(request, status, error) {
        $(errorDialog).html(error);
        $(errorDialog).dialog('open');
        return false;
    },
    complete: function() {
        //do something
    }
});

当我点击按钮来触发Ajax请求,DevTools显示以下错误:

and when I click on the button to fire the Ajax request, the DevTools show the following error:

POST > http://localhost:8080/GrailsTest001/authentication/$%7Bg.createLink(controller:'userSearch',action:'ajaxFindUser')%7D 404 (Not Found) 

所以,你可以看到,该URL获取的HTML连接codeD ...如何从编码它,我prevent Grails的?

so, as you can see, the URL get's HTML encoded... how can I prevent Grails from encoding it?

Config.groovy中的codeC设置为

in Config.groovy the codec is set to none:

// The default codec used to encode data with ${}
grails.views.default.codec = "none" // none, html, base64

我究竟做错了什么?你能不能给我任何提示(或更好:一溶液)呢?任何帮助是极大的AP preciated!

what am I doing wrong here? could you give me any hint (or better: a solution) for this? any help is greatly appreciated!

推荐答案

普惠制段

 ${createLink(controller:'userSearch',action:'ajaxFindUser')}

没有得到除preTED - 这是在JavaScript文件中或在实际GSP?它看起来像它在JavaScript文件中定义。如果是这样,它不会工作,你需要创建GSP页面上的一个JavaScript变种,然后引用了JavaScript变种从你的Ajax调用。例如:

is not getting interpreted - is this in a javascript file or in actual GSP? It looks like it's defined in a javascript file. If so, it won't work, you'll need to create a javascript var on the GSP page, and then reference that javascript var from your ajax call. For example:

在你的GSP code:

In your GSP code:

<g:javascript>
  var ajaxAction = "${createLink(controller:'userSearch',action:'ajaxFindUser')}"
</g:javascript>

在你包含了ajax code javascript文件:

In your javascript file containing the ajax code:

$.ajax({
    type: 'POST',
    url: ajaxAction,
    dataType: 'json',
    data: {
  ...

这篇关于Grails的jQuery的Ajax请求 - URL不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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