简体   繁体   English

jQuery对话框和Ajax回发

[英]jQuery dialog and ajax postback

A page on my site are auto-reloading every 15th second. 我网站上的页面每15秒钟自动重新加载一次。 It's being done by using jQuery's .ajax function. 这是通过使用jQuery的.ajax函数完成的。

My problem are, that everytime the page are being loaded by the user, the form in the dialogs work fine. 我的问题是,每次用户加载页面时,对话框中的表单都可以正常工作。 But when it's reloaded automatically by the page itself, the inputs are being moved OUTSIDE the form. 但是,当页面本身自动重新加载它时,输入将移到表单外。

Many on the internet writes, that it is possible to move it back into the form by appending a div into the first form found. 互联网上的许多人写道,可以通过将div附加到找到的第一个表单中来将其移回到表单中。 My problem is, that when i try to move my "input-wrapper" back into the form, i get a hirachy-problem. 我的问题是,当我尝试将“输入包装”移回表格时,出现了一个问题。

Can anyone help? 有人可以帮忙吗? Or point out an alternative solution? 或指出替代解决方案?

My jQuery-script: 我的jQuery脚本:

<script type='text/javascript'>
  var intval;
  var xmlhttp;
  function init() {
    $('#dialog:ui-dialog').dialog('destroy');
    $('.ui-dialog').dialog({ modal: true, draggable: false, resizable: false, autoOpen: false, open: function(event, ui) { stopTimer(); }, close: function(event, ui) { startTimer(); } });
    $('#targets').dialog({ width: 400, buttons: { 'close': { text: 'Luk', height: '30px', click: function() { $(this).dialog('close'); } }, 'submit': { text: 'OK', class: 'submit', height: '30px', click: function() { $(this).find('form').trigger('submit'); } } } });
    $('#targets" & id2 & "Opener').click(function() { $('#targets').dialog('open'); return false; });
  };
  function startTimer() { intval = setTimeout('ajaxRefresh()', 15000); };
  function stopTimer() { clearTimeout(intval); if(xmlhttp) xmlhttp.abort(); };
  function ajaxRefresh() { xmlhttp = $.ajax({ url: '/', data: {h: 'ok'}, beforeSend: function() { stopTimer(); }, success: function(result) { $('body').html(result); } } }) };
  $(document).ready(function() { init(); startTimer(); $('#targetsFormWrap').parent().appendTo('#targetsForm'); });
</script>

The HTML: HTML:

<div id='targets' class='ui-dialog' title='The Dialog Title' style='text-align: center; display: none;'>
  <form id='targetsForm' name='targetsForm' method='post'>")
    <div id='targetsFormWrap'>")
      <input id='input1target' name='input1target' type='text' value='' style='width: 95%; />
      <input id='input2target' name='input2target' type='text' value='' style='width: 95%; />
      <input id='input3target' name='input3target' type='text' value='' style='width: 95%; />
    </div>
  </form>
</div>

you are trying to add targetFormWrap to targetsForm right? 您正在尝试将targetFormWrap添加到targetForm对吗? so just do: 所以做:

$("#targetsForm").append($("#targetsFormWrap"));

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

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