简体   繁体   English

X可编辑的表单,将Ajax加载到div中

[英]x-editable form loaded with ajax into a div

I want to load a form directly into a using ajax call. 我想使用ajax调用直接将表单加载到。

The container page has already all the needed css/scripts inclusion for x-editable forms. 容器页面已经包含了x可编辑表单所需的所有CSS /脚本。

I can load the html code directly inside the div, but the problem is that the x-editable fields are not rendered. 我可以直接在div内加载html代码,但是问题是x可编辑字段未呈现。 Here is my code: The div that will contain the remote content 这是我的代码:包含远程内容的div

<div id="mycontent">
....
</div>

And the javascript function: 和javascript函数:

 $("#create-button").click(function(){
    document.location.href = '/fip-dt/insertProject';
    $('#mycontent').html('');
    ajaxRead('/insertProject');
 });

 function ajaxRead(file){
   var htmlObj = null;
   if(window.XMLHttpRequest){
       htmlObj = new XMLHttpRequest();
   } else if(window.ActiveXObject){
       htmlObj = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
       return;
   }
   htmlObj.onreadystatechange = function(){
     if(htmlObj.readyState == 4){
        updateObj(htmlObj);
      }
     }
     htmlObj.open ('GET', file, true);
     htmlObj.send ('');
   }
   function updateObj(data){
    document.getElementById("mycontent").innerHTML=data.responseText;
   }

I cannot use jquery directly to updated the content of div, because it seems to entirely remove the tags. 我不能直接使用jquery来更新div的内容,因为它似乎完全删除了标签。

Into the remote div, i have the following javascript code: 进入远程div,我有以下javascript代码:

$.fn.editable.defaults.mode = 'inline';
$('table#projectform > tbody > tr > td > a').editable();
$('.myeditable').editable({
    url: '/post'
});
$('#project-name').editable('option', 'validate', function(v){
    if(!v) return 'Required Field';
});
$('#save-btn').click(function(){
    $("p#prova").html("TEST");
}); 

It seems that this piece of code is not executed when the remote content is loaded into the div. 似乎在将远程内容加载到div中时未执行这段代码。

Any idea? 任何想法?

渲染div后尝试添加代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM