javascript
  • php
  • database
  • post
  • 2015-07-13 20 views 0 likes 
    0

    我想將表單的值發佈到兩個數據庫。 其中一個是本地的,一個不是。這就像客戶端的「備份」。發佈在兩個php腳本上。

    我現在的問題是我必須使用「POST」方法並將值傳遞給兩個不同的腳本。我不知道我該怎麼做。我的服務器不支持捲曲

    這是我在用的:

    <form action="" method="post" enctype="multipart/form-data" id="form"> 
    <table cellspacing='0' onkeydown='return editingKeydown(event);'> 
    <tr><th>first_name<td class='function'>*<td><input value='' maxlength='100' size='40' id='first_name' name='first_name'> 
    <tr><th>last_name<td class='function'>*<td><input value='' maxlength='100' size='40' id='last_name' name='last_name'> 
    <tr><th>company<td class='function'>*<td><input value='' maxlength='100' size='40' id='company' name='company'> 
    <tr><th>phone<td class='function'>*<td><input value='' maxlength='100' size='40' id='phone' name='phone'> 
    <tr><th>email<td class='function'>*<td><input value='' maxlength='100' size='40' id='email' name='email'> 
    <tr><th>zip<td class='function'>*<td><input value='' maxlength='100' size='40' id='zip' name='zip'> 
    <tr><th>street<td class='function'>*<td><input value='' maxlength='100' size='40' id='street' name='street'> 
    <tr><th>city<td class='function'>*<td><input value='' maxlength='100' size='40' id='city' name='city'> 
    <tr><th>state<td class='function'>*<td><input value='' maxlength='100' size='40' id='state' name='state'> 
    <tr><th>country<td class='function'>*<td><input value='' maxlength='100' size='40' id='country' name='country'> 
    <tr><th>reasons<td class='function'>*<td><input value='' maxlength='300' size='40' id='reasons' name='reasons'> 
    <tr><th>notes<td class='function'>*<td><input value='' maxlength='300' size='40' name='notes' id='notes'> 
    <tr><th>callback<td class='function'>*<td><input value='' maxlength='100' size='40' id='callback' name='callback'> 
    </table> 
    <p> 
    <input type='submit' value='Salvează' onclick='javascript: return SubmitForm()'> 
    
    
    </form> 
    
    <script type='text/javascript'> 
    
    function SubmitForm() 
    { 
        if(document.forms['form'].onsubmit()) 
        { 
         document.forms['form'].action='http://www.example.com/script1.php'; 
         document.forms['form'].submit(); 
    
         document.forms['form'].action='preproc.php'; 
         document.forms['form'].submit(); 
        } 
        return true; 
    } 
    
    
    
    </script> 
    

    這不是爲我工作。你知道我能做到這一點嗎?即使是替代品...

    謝謝你的回答。

    +0

    定期進行數據庫的備份可以通過服務器應用程序可以輕鬆完成。是否有任何其他具體原因做到這一點。 – siddhesh

    +0

    我會選擇做數據庫複製或定期轉儲(情況依賴)而不是這個。如果其中一個帖子失敗,你會怎麼做?將有一個不匹配。 – frz3993

    +0

    客戶需要我爲此使用「後」方法。我也會去備份方法。 –

    回答

    0

    嘗試使用jQuery.Deferred();https://api.jquery.com/category/deferred-object/

    這樣,你的請求將在同一時間被髮送,這是更快:

    $("#some-form").on("submit", function(e) { 
        e.preventDefault(); 
        var formOneDeferred = $.post({ ... }), 
         formTwoDeferred = $.post({ ... }); 
    
        /** 
        * Handler will only be triggered if and when both submits succeed 
        */ 
        $.when(formOneDeferred, formTwoDeferred, function(firstSubmitResults, secondSubmitResults) { 
         console.log('Process submit results', firstSubmitResults, secondSubmitResults); 
        }); 
    }); 
    
    +1

    謝謝,我會對它進行測試,並回復如何以及如何幫助我。 /我讀過一些瀏覽器放棄其中一個提交,只有幾個提交兩個,所以這可能正是我所需要的。再次感謝您的評論。 –

    相關問題