jQuery的POST表单数据

jQuery的POST表单数据

本文介绍了jQuery的POST表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击提交我希望所有的表单数据被张贴到process.php所有我想做的事就是......然后process.php我想呼应了POST数据......然后替换一切结果DIV什么是在process.php ...

完成

 <脚本类型=文/ JavaScript的>
        $(文件)。就绪(函数(){


            $(#MyForm的)。递交(函数(){
                                $阿贾克斯({
                                    键入:POST,
                                    数据类型:HTML,
                                    缓存:假的,
                                    网址:process.php
                                    成功:功能(数据){
                                        $(#结果)HTML(数据);
                                    }
                                });
                                返回false;
            });


            // $(#MyForm的)。递交(函数(){

                        //$('#results').html("yay);
                    //}

                //});
            //});




        });
        < / SCRIPT>
 

   

 <表格名称=MyForm的ID =MyForm的行动=的方法=POST>
<! - 该名称的表单字段 - >
    <标签=名称ID =name_label>放大< /标签>
    <输入类型=文本名称=放大ID =缩放大小=30值=/>
    < BR>
< /选择>


<! - 提交按钮 - >
    <输入类型=提交名称=提交值=提交>
< /形式GT;

<! - 成型时----------------------------------------  - &GT ;


<! - 结果START ----------------------------------------  - &GT ;
    < D​​IV ID =结果> nooooooo< PHP $ _SESSION ['']>< D​​IV>
    <! - <输入类型=形象NAME =mapcoords边界=0SRC =mapgen.php> ----  - >
<! - 结果落得----------------------------------------  - &GT ;
 

系列化解决方案

您可以致电 $。交传递表单数据。像这样的:

 <脚本类型=文/ JavaScript的>
        $(文件)。就绪(函数(){
            $(#MyForm的)。递交(函数(){
              $。员额(
               process.php,
                $(本).serialize()
                功能(数据){
                  $(#结果)。HTML(数据)
                }
              );
              返回false;
            });
        });
< / SCRIPT>
 

all i want to do is when i click submit i want all form data to be POSTed to process.php... then on process.php i want to echo out the POST data... then replace everything in results div to what was done in process.php...

<script type="text/javascript">
        $(document).ready(function(){


            $("#myform").submit( function () {
                                $.ajax({
                                    type: "POST",
                                    dataType: "html",
                                    cache: false,
                                    url: "process.php",
                                    success: function(data){
                                        $("#results").html(data);
                                    }
                                });
                                return false;
            });


            //$("#myform").submit( function () {

                        //$('#results').html("yay");
                    //}

                // });
            //} );




        });
        </script>
<form name="myform" id="myform" action="" method="POST">
<!-- The Name form field -->
    <label for="name" id="name_label">zoom</label>
    <input type="text" name="zoom" id="zoom" size="30" value=""/>
    <br>
</select>


<!-- The Submit button -->
    <input type="submit" name="submit" value="Submit">
</form>

<!-- FORM END ----------------------------------------  -->


<!-- RESULTS START ---------------------------------------- -->
    <div id="results">nooooooo<?PHP $_SESSION[''] ?><div>
    <!-- <input type="image" name="mapcoords" border="0" src="mapgen.php"> ---- -->
<!-- RESULTS END ---------------------------------------- -->
解决方案

You can call $.post passing form data serialized. like this:

<script type="text/javascript">
        $(document).ready(function(){
            $("#myform").submit( function () {
              $.post(
               'process.php',
                $(this).serialize(),
                function(data){
                  $("#results").html(data)
                }
              );
              return false;
            });
        });
</script>

这篇关于jQuery的POST表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:45