js在不跳转的情况下向一个页面传递参数

需求是把textarea传递到savexml.php进行数据保存,但同时我希望页面还留着当前页面。
代码如下:

 <form name="form1" id="form1" method="post" action="newtest.php">
            <input type="hidden" name="text1" value="<?php echo $text1;?>" size="30"/><br>
            <textarea name="textarea1" rows="10" cols="150"><?php echo $text1;?></textarea><br>
            <input type="button" name="finish" value="完成拆分"  onClick="save()"   />
        </form>

 function save(){
               //省略的代码是获得textarea的值
                var formdeal= document.getElementById("form1");
                 formdeal.action="savexml.php?parms="+str;
               formdeal.target="_self";
                formdeal.submit();}
后台接收如下:<?php
       $str1=$_REQUEST['parms'];?>

可用
1. ajax 技術





<br> var Submit=function(){<br> var URLs=&quot;接收檔.php&quot;;</p> <pre><code> $.ajax({ url: URLs, data: $(&#39;#sentToBack&#39;).serialize(), type:&quot;POST&quot;, dataType:&#39;text&#39;, success: function(msg){ alert(msg); }, error:function(xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(thrownError); } }); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;sentToBack&quot;&gt; &lt;input type=&quot;text&quot; name=&quot;Text&quot;/&gt; &lt;input type=&quot;button&quot; value=&quot;送出&quot; onClick=&quot;Submit()&quot;/&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p></html></p> <ol> <li>若不喜 ajax 或 jquery, 可用 iframe 或 隱藏的 frame 將 target 設為那個 iframe 或 frame, 讓 form1 傳到那個 iframe 或 frame 去運行,在回傳時以 javascript 通知當前頁面</li> </ol>

ajax正解,这就是异步同步技术。但是如果写Ajax源码太过复杂,建议配合jquery使用

 <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
 <form name="form1" id="form1" method="post" action="newtest.php">
            <input type="hidden" name="text1" value="<?php echo $text1;?>" size="30"/><br>
            <textarea name="textarea1" rows="10" cols="150"><?php echo $text1;?></textarea><br>
            <input type="button" name="finish" value="完成拆分"  onClick="save()"   />
        </form>
<script>
    function save() {
        $.ajax({ url: 'savexml.php',type:'POST', data: $('#form1').serialize(), complete: function (xhr) {
            if (200 == xhr.status) alert('请求成功!')
            else alert('动态页有问题!\n' + xhr.responseText)
        } 
        });
    }</script>

后台接收如下:

 <?php
       $text1=$_POST['text1'];
       $textarea1=$_POST['textarea1'];?>

建议使用jquery 中的$post

使用ajax就可以了。
http://www.w3school.com.cn/jquery/jquery_ajax_intro.asp

难一点的AJAX,小白就用form 的target属性模拟无跳转。主要还是看需求。如果需要回调函数的话,毫无疑问,AJAX才能满足