开发者

html() strips script tags in fancybox (jQuery) ajax call

My issue is quite similar to these ones:

  • jquery html() strips out script tags
  • jQuery - script tags in the HTML are parsed out by jQuery and not executed

But this is a particular case and none of them worked for me.

I am using the fancybox (1.3.4) jQuery plugin to display the result of an ajax call which returns an HTML string. The HTML string contains an ajax form with jQuery lines, which are not outputting because of the html() function. I tried replacing it by innerHTML (which is actually the same as html()) or replacing the tags by others and then updating it but nothing worked.

If you want to know exactly where this happens it's line 265 in the fancybox JS file.

Any ideas how to solve this?

Cheers,

Nicolas.

EDIT: an example of the code retreived by ajax containing the <script> tag:

<div class="ddinline">
    <form id="form542612422" onsubmit="return false;" update="searchbtn" position="before" me开发者_开发百科thod="post" action="/Librariescategories/AJAXGetChildrenList" accept-charset="utf-8">
        <div style="display:none;">
            <input type="hidden" name="_method" value="POST" />
        </div>
        <script type="text/javascript">
        //<![CDATA[
        $('#form542612422').bind('submit', function(){ $.ajax({async:true, type:'post', beforeSend:function(request) {$("#filter .ddinline").last().after('<img src="/img/loading.gif" id="catload" alt="" />');}, complete:function(request, json) {$('#searchbtn').before(request.responseText); $("#catload").remove(); createDropDown($("#filter .fulldrop").last());}, data:$('#form542612422').serialize(), url:'/Librariescategories/AJAXGetChildrenList'}) })
        //]]>
        </script>
        <select name="data[Librariescategories][id]" class="fulldrop" id="LibrariescategoriesId">
            <option value="0" selected="selected">select</option>
            <option value="1">3D Models</option>
            <option value="259">Imagery</option>
            <option value="362">Textures</option>
       </select>
       <div class="hide">
           <input type="submit" value="Submit" />
       </div>
    </form>
</div>


I think you might need to add your script and html something separately. You can send the markup and script joined by a token over the wire. Split them up via javascript on the client. Then add the html into the fancybox element. The script may need to be added outside the fancybox element. Here is an example of how to add the html and script into the same element:

http://jsbin.com/otage3/2/edit

Hope this helps.

Bob

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜