Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax Twitter引导模式调用控制器操作_Ajax_Grails_Twitter Bootstrap - Fatal编程技术网

Ajax Twitter引导模式调用控制器操作

Ajax Twitter引导模式调用控制器操作,ajax,grails,twitter-bootstrap,Ajax,Grails,Twitter Bootstrap,我有一个使用twitter引导模式的弹出窗口。我想在弹出窗口显示之前调用控制器操作,并在弹出窗口中显示控制器操作的变量值。ajax没有调用控制器操作。还有别的办法吗 我的普惠制: $(文档).ready(函数(){ $('#myModal')。on('show',function(){ $.ajax({ 键入:“获取”, url:“${createLink(控制器:'MgMatrix',操作:'popup')}” }).完成(功能(数据){ $('#模态体').html(数据); }); }

我有一个使用twitter引导模式的弹出窗口。我想在弹出窗口显示之前调用控制器操作,并在弹出窗口中显示控制器操作的变量值。ajax没有调用控制器操作。还有别的办法吗

我的普惠制:


$(文档).ready(函数(){
$('#myModal')。on('show',function(){
$.ajax({
键入:“获取”,
url:“${createLink(控制器:'MgMatrix',操作:'popup')}”
}).完成(功能(数据){
$('#模态体').html(数据);
});
});//结束于()
});//结束就绪()
×
模态头
一些内容


您的代码非常完美,在代码中做了一点小小的更改后,它就适合我了

您正在使用表示id而不是类的#

$('#modal-body').html(data);
替换为

e、 g

试试这个,享受

编辑

        $.ajax({
          type: "GET",
          url: "${createLink(controller: 'mGMatrices', action: 'popup')}",
          data: "inputField="+$("[name='inputField']").val()+"&fieldName="+$("[name='fieldNAme']").val()
        }).done(function(data) {
            $('#modal-body').html(data);
        });

您的评论问题:

I need to call first the action in the controller before displaying the popup.
答:按照说明稍微更改代码

<g:javascript>
    function callMe(){
      $.ajax({
      type: "GET",
      url: "${createLink(controller: 'mGMatrices', action: 'popup')}",
      data: "aa="+$("[name='inputField']").val()
        }).success(function(data) {
            $('.modal-body').html(data);
            $('#myModal').modal('show');
        });
    }
</g:javascript>

<g:textField name="inputField"/>
<!-- Button to trigger modal -->
<a href="javascript:void(0)" class="btn" onclick="callMe()">Launch demo modal</a>



<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

        <h3 id="myModalLabel">Modal header</h3>
    </div>

    <div class="modal-body">
        <p>some content</p>
        <input type="text" name="bookId" id="bookId" value=""/>
    </div>
</div>

函数callMe(){
$.ajax({
键入:“获取”,
url:“${createLink(控制器:'MgMatrix',操作:'popup')}”,
数据:“aa=”+$(“[name='inputField']”)val()
}).成功(功能(数据){
$('.modal body').html(数据);
$('myModal').modal('show');
});
}
×
模态头
一些内容


您是否收到任何javascript错误?它可以正常工作。但我需要在控制器内获取文本框输入。当我打印params.inputField时,它仍然为空。哇,太好了。另外,在显示弹出窗口之前,我需要首先调用控制器中的操作。提前谢谢,非常感谢。但我还有最后一点担心。在控制器操作上,我有一个返回值,我需要在弹出窗口中显示该返回值。提前谢谢。如果你在你的控制器中使用了return关键字,那么请用render替换它,你会得到值(我认为)。还有一件事,如果你的问题解决了,请投票赞成答案。
I need to call first the action in the controller before displaying the popup.
<g:javascript>
    function callMe(){
      $.ajax({
      type: "GET",
      url: "${createLink(controller: 'mGMatrices', action: 'popup')}",
      data: "aa="+$("[name='inputField']").val()
        }).success(function(data) {
            $('.modal-body').html(data);
            $('#myModal').modal('show');
        });
    }
</g:javascript>

<g:textField name="inputField"/>
<!-- Button to trigger modal -->
<a href="javascript:void(0)" class="btn" onclick="callMe()">Launch demo modal</a>



<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

        <h3 id="myModalLabel">Modal header</h3>
    </div>

    <div class="modal-body">
        <p>some content</p>
        <input type="text" name="bookId" id="bookId" value=""/>
    </div>
</div>