douzhuan1432 2015-06-12 10:57
浏览 90
已采纳

当值被POST时,jQuery setTimeout刷新

Previously i was sending values through GET from onChange of select dropdown

<select name="addSel" id="addSel" onChange="addFunc(this.value);">
    <option></option> ....  <option></option>
</select>

and in my javascript

function addFunc(val)
{
   document.location = 'index.php?action=live&sub=add';
}

I could possibly refresh my HTML table with the condition sub=add and table contents dependant on sub=add

function refTbl()
{
    var pathtopage = window.location.href;
    $('#TableId').load(pathtopage + ' #TableId', function(){
        setTimeout(refTbl, 10000);
    });
}

Then i wrapped my select inside <form> to send values through POST

<form id="selForm" name="selForm" action="" method="POST">
  <select name="addSel" id="addSel" onchange="this.form.submit()">
        <option></option> ....  <option></option>
  </select>
</form>

My url remains index.php?action=live and cant able to refresh my table based on posted values

function refTbl()
{
    var pathtopage = 'index.php?action=live';
    $('#TableId').load(pathtopage + ' #TableId', function(){
         setTimeout(refTbl, 10000);
    });
}

This doesn't refresh my table based on values from POST through select onChange. how it is possible to refresh my HTML table using setTimeout based on POST values.

p.s - I dont want to use AJAX

  • 写回答

1条回答

  • dongyied24121 2015-06-12 11:04
    关注

    jQuery .load() second optional parameter is data. Send your form data with this.

    You have to serialize your form data.

    function refTbl(e)
    {
        // Prevent form reloading page
        e.preventDefault();
        var pathtopage = 'index.php?action=live';
        var data = $(this).serializeArray();
        $('#TableId').load(pathtopage + ' #TableId', data, function(){
             setTimeout(refTbl, 10000);
        });
    }
    

    And call it on form submit

    $("#selForm").submit(refTbl);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 虚心请教几个问题,各位DS,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题