2012-07-02 93 views
0

我需要將數據表單#send_form提交到另一個頁面中的#f_from的幫助。將表格提交到其他頁面

<script type="text/javascript"> 
function post_form() { 
    $('#send_form').action = "form01.html"; 
    $('#send_form').submit(); 
    return false;  
} 
</script> 

<form id='send_form' action='form01.html' method='POST' onsubmit="post_form();"> 
<input type="text" name="f_in01" value="User" /> 
<input type="text" name="f_in02" value="12345" /> 
<input type="submit" /> 
</form> 

的form01.html

<script type="text/javascript"> 
function f_res() 
{ 
    var res01=document.f_form.f_in01.value; 
    var res02=document.f_form.f_in02.value; 
    var result = res01 + " " + res02; 
    document.f_form.f_out01.value=result; 
} 
</script> 

<form id="f_form" onSubmit="f_res();return false;"> 
<input type="text" name="f_in01" /><br> 
<input type="text" name="f_in02" /><br> 
<br> 
<input type="submit" onClick="f_res();" value="Enter w/Sub" /><br> 
<input type="text" name="f_out01" /> 
</form> 

現在這是行不通的。該數據不page01.html發佈

+0

這讓很少的感覺。請添加更多的細節和澄清。 – sachleen

+0

嗯,你知道如果你打算向URL「form01.html」發出一個POST請求,你的HTTP服務器需要以某種方式處理?你不能只提供一個靜態文件「form01.html」,並期望它神奇地知道什麼形式的數據提出請求。您是否期望數據以某種方式呈現在form01.html的元素中,僅僅因爲它們具有相同的名稱屬性?這不是HTTP/HTML的工作原理。 –

回答

0

你試過

$('#send_form').attr('action', "form01.html"); 

,而不是

$('#send_form').action = "form01.html"; 

退房this fiddle

+0

Thx。我做到了。但它仍然不會將數據發佈到其他頁面。 –

0

阿明是正確的,但在jQuery的,當事件處理程序返回false,它等於e.preventDefault(); e.stopPropagation()。基本上,你取消了這個事件。嘗試返回true,而不是false。

如果您不希望頁面發生變化,您必須查看AJAX以發佈表單數據。

0

你想AJAX此類似:

$('#button').click(function(){ 
    $.ajax({ 
    type:"POST", //php method 
    url:'process.php',//where to send data... 
    cache:'false',//IE FIX 
    data: data, //what will data contain (no SHIT Sherloc...) 

    //check is data sent successfuly to process.php 
    //success:function(response){ 
    //alert(response) 
    //} 

    success: function(){ //on success do something... 

    $('.success').delay(2000).fadeIn(1000); 

    //alert('THX for your mail!'); 
    } //end sucess 
    }).error(function(){ //if sucess FAILS!! 
    alert('An error occured!!'); 
    $('.thx').hide(); 
    }); 
    });