I create a social network with Grails and get stuck on giving users the internal page editing file the ability to paste the youtube-url URL into the text field and by pressing the JS button it gives the id from the inserted URL, the ajax message starts with updating the div with a preview image of youtube video
html looks like this:
<g:textField name="videoinput" class="videoinput reLef" value="" /> <span class="daten_videouploadbtn reLef" ></span> <g:render template="/forms/storedVideos" />
JS looks like this:
$('.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){} }); });
the controller is as follows:
def addVideo() { def videoitems = !!%%-- HOW TO PARSE YOUTUBE-ID HERE -%%!! render(template:"/forms/storedVideos", model: [newVideo:videoitems]) }
and saved videos look:
<div id="storedvideos"><span><img src="http://img.youtube.com/vi/${newVideo}/default.jpg" width="225px" height="130px"/></span></div>
I just donβt understand how to catch Ajax Post data and update div with preview image with id inside,
Can someone tell me? this is killing me
source share