路过的AJAX POST参数来Grails的控制器 [英] Passing Parameters of AJAX POST to Grails Controller

查看:289
本文介绍了路过的AJAX POST参数来Grails的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm建立社交网络,Grails和得到stucked 在给用户在内的editprofile 页面机会粘贴YouTube的URL转换为文本框,并通过点击一个按钮,一个JS regexxes标识出粘贴的URL,一个ajax后触发更新一个div与YouTube视频的preVIEW图像

I´m building a social network with Grails and got stucked on giving users inner their editprofile page the chance to paste an youtube-Url into a textfield and by clicking a button a JS regexxes the id out of the URL pasted, an ajax post is fired updating a div with a preview image of the youtube video

在html如下:

                    <g:textField name="videoinput" class="videoinput reLef" value="" />
                    <span class="daten_videouploadbtn reLef" ></span>

        <g:render template="/forms/storedVideos" />

JS的样子:

the JS looks like :

    $('.daten_videouploadbtn').click(function() {

        var string = document.editProfileForm.videoinput.value;
        var neu = string.replace(/http[s]?:\/\/(?:[^\.]+\.)*(?:youtube\.com\/(?:v\/|watch\?(?:.*?\&)?v=|embed\/)|youtu.be\/)([\w\-\_]+)/i, '$1'); 
        var id = RegExp.$1;

        jQuery.ajax({
        type:'POST',
        data:RegExp.$1, 
        url:'${createLink(action: 'addVideo')}',
        success:function(data,textStatus){jQuery('#storedvideos').html(data);},
        error:function(XMLHttpRequest,textStatus,errorThrown){}
        });
});

控制器是这样的:

def addVideo() {
    def videoitems = !!%%-- HOW TO PARSE YOUTUBE-ID HERE -%%!!
    render(template:"/forms/storedVideos", model: [newVideo:videoitems])
}

和存储视频的样子:

    <div id="storedvideos"><span><img src="http://img.youtube.com/vi/${newVideo}/default.jpg" width="225px" height="130px"/></span></div>

我只是不明白它如何捕捉到阿贾克斯后的数据并更新与该ID里面的preVIEW形象的股利,

i just dont get it how to catch the data of the Ajax Post and update the div with the preview image with the id inside,

有人可以给出一个提示?这是我的命

can someone give a hint ? it is killing me

推荐答案

您应该张贴的数据是这样的:

You should post the data like this:

jQuery.ajax({
  type: 'POST',
  data: { value: RegExp.$1 },
  ...

之后,你可以用 params.value 访问你的Grails控制器内发布的数据。

After that you can access the posted data inside your grails controller with params.value.

这篇关于路过的AJAX POST参数来Grails的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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