<INPUT name=text class="inp" id="text" size=15 maxLength=40> 
<INPUT name=text1 type=text1 class="inp" id="text1">获取text和text1两个表单的数据,然后发送到PHP接收,代码怎么写,求好心人,求版主javascriptjsphp数据

解决方案 »

  1.   

    增加form标签。提交时就自动发送到php文件去了。
    或者使用js先获取text和text1的内容,然后通过ajax发送到php去。
      

  2.   

    form submit
    或者 ajax  
      

  3.   

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script>
        function check(form) {
            $.ajax({ type: 'POST', data: $(form).serialize(), url: 'xxx.php', dataType: 'html', complete: function (xhr) {
                if (xhr.responseText == '1') alert('OK');
                else alert(xhr.responseText);
            }
            });
        }
          
    </script>
    </head>
    <body>
    <form onsubmit="return check(this)">
    <INPUT name=text class="inp" id="text" size=15 maxLength=40> 
    <INPUT name=text1 type=text1 class="inp" id="text1">
     
    <input type="submit" value="submit" />
    </form>
    </body>
    </html>
    xxx.php
    $text=$_POST["text"];
    $text1=$_POST["text1"];
    //...其他代码echo "1";
    die();
      

  4.   

    感谢版主,我想获取一下当前的URL也发送到PHP上去怎么写?还有能不能隐藏提交后URL后面的参数?
      

  5.   

    当前地址的url是location.href,直接添加就行了<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script>
        function check(form) {
            $.ajax({ type: 'POST', data: $(form).serialize()+'&url='+encodeURIComponent(location.href), url: 'xxx.php', dataType: 'html', complete: function (xhr) {
                if (xhr.responseText == '1') alert('OK');
                else alert(xhr.responseText);
            }
            });
        }
           
    </script>
    </head>
    <body>
    <form onsubmit="return check(this)">
    <INPUT name=text class="inp" id="text" size=15 maxLength=40> 
    <INPUT name=text1 type=text1 class="inp" id="text1">
      
    <input type="submit" value="submit" />
    </form>
    </body>
    </html>
      

  6.   

    <INPUT name=text class="inp" id="text" size=15 maxLength=40> 
    <INPUT name=text1 type=text1 class="inp" id="text1">什么东西。不伦不类的。
      

  7.   

    版主,只能接收到text和text1的数据,接收不到location.href啊
      

  8.   

    <?php 
    if(isset($_POST['text'])&&isset($_POST['text1'])) 

        $string = "text:".$_POST['text']." text1:".$_POST['text1']."\r\n"; 
        $file = fopen("1.txt", "a"); 
        fwrite($file, $string); 
        fclose($file); 

    ?>
    我的PHP是这样写的,这样只能接收到text和text1的数据保存1.txt文件里,location.href怎么接收?
      

  9.   

    你没写入传递的URL参数啊。。<?php 
    if(isset($_POST['text'])&&isset($_POST['text1'])) 

        $string = "text:".$_POST['text']." text1:".$_POST['text1']." URL:".$_POST['URL']."\r\n"; 
        $file = fopen("1.txt", "a"); 
        fwrite($file, $string); 
        fclose($file); 

    ?>
      

  10.   

    你按照#5加上了url递交的数据没了。。然后按照#9的接受数据后写入文件
      

  11.   


    php的$_POST获取键值区分大小写的??URL改成url就行了,发送的数据键名称是小写的$string = "text:".$_POST['text']." text1:".$_POST['text1']." URL:".$_POST['url']."\r\n"; 
      

  12.   

    万分感谢版主,我想问下url后面不用参数行不行,不用参数好像发送不成功的
      

  13.   

    $.ajax({ type: 'POST', data: $(form).serialize()+'&url='+encodeURIComponent(location.href.replace(location.search,'')),
      

  14.   

    版主,不行啊
    http://localhost/aa.htm?text=123&text1=123
    提交后URL变成这样,我想不要出现"?text=123&text1=123“
    就http://localhost/aa.htm行了
      

  15.   

    本帖最后由 showbo 于 2013-10-30 14:48:28 编辑