javascript
  • php
  • database
  • post
  • 2015-07-13 73 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

    谢谢,我会对它进行测试,并回复如何以及如何帮助我。 /我读过一些浏览器放弃其中一个提交,只有几个提交两个,所以这可能正是我所需要的。再次感谢您的评论。 –

    相关问题