简体   繁体   English

在两个php脚本上发布信息。

[英]POST-ing on two php scripts.

I am trying to post the values of a form to two databases. 我正在尝试将表单的值发布到两个数据库。 One of them is local, one is not. 其中之一是本地的,一个不是本地的。 It's like a "backup" for the client. 这就像客户端的“备份”。

My problem now is that I have to use the "POST" method and pass the values to two different scripts. 我现在的问题是我必须使用“ POST”方法并将值传递给两个不同的脚本。 I have no idea how i can do that. 我不知道我该怎么做。 My server does not support curl 我的服务器不支持curl

This is what i am using : 这就是我正在使用的:

<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>

This is not working for me. 这对我不起作用。 Do you know of any way I can do this? 你知道我能做到吗? Even alternatives... 甚至替代品...

Thank you for your answers. 谢谢您的回答。

Try using jQuery.Deferred(); 尝试使用jQuery.Deferred(); ( https://api.jquery.com/category/deferred-object/ ) https://api.jquery.com/category/deferred-object/

This way your requests will be sent at the same time, which is faster: 这样,您的请求将在同一时间发送,这是更快的:

$( "#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 );
    });
});

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

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