Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP中的formaction语句_Javascript_Php_Ajax_Forms_Post - Fatal编程技术网

Javascript PHP中的formaction语句

Javascript PHP中的formaction语句,javascript,php,ajax,forms,post,Javascript,Php,Ajax,Forms,Post,我的PHP代码有以下问题: 我的表单分为两个div:第一个div在页面打开时显示,第二个div在单击按钮后显示(第一个div由于Ajax而隐藏)。我的计划是检查一些语句,如果为true,则创建POST,从中获取数据,然后动态创建表,再次使用Ajax切换内容。但是因为这些陈述,我不能使用“动作”这个词。当我使用“提交”类型时,它会创建帖子,但会重新加载页面。如果我用“按钮”类型替换它——Ajax可以工作,但POST是空的。 这是我的密码: function formu ($w="1",

我的PHP代码有以下问题: 我的表单分为两个div:第一个div在页面打开时显示,第二个div在单击按钮后显示(第一个div由于Ajax而隐藏)。我的计划是检查一些语句,如果为true,则创建POST,从中获取数据,然后动态创建表,再次使用Ajax切换内容。但是因为这些陈述,我不能使用“动作”这个词。当我使用“提交”类型时,它会创建帖子,但会重新加载页面。如果我用“按钮”类型替换它——Ajax可以工作,但POST是空的。 这是我的密码:

     function formu ($w="1", $sr="on", $comma="", 
     $space ="",  $other =""){?>
     <form id="options"  action="" method="POST" >
     <div id = "first">
     <h1 id = "title"> Choose a file </h1>
     <input type = "radio" name="radio" id ="radio" value="op1" class ="radio"> ONE
     <br>
     <input type ="radio" name="radio" id="radio" value ="op2" class = "radio"> TWO
     <br>
     <input type ="radio" name="radio" id="radio" value="op3" class = "radio"> THREE
    <br>
    <input type = "button" id="Submit" Value = "Show">
    </div>
    <div id = "sec">
    <h1 id = "title2"> Choose options </h1>
    <p id="odwiersza"> Cut: </p> 
    <input type="text" name="w" value=""> <br>
    <p id="Separators"> Separator: </p>
    <input type = "checkBox" name="sr"> sr 
    <input type= "checkBox" name="comma"> comma
    <input type = "checkBox" name = "space"> space  
    <input type = "checkBox" name ="other"> other (which?) <input type="text" name="such">
    <br>
    <input type="submit" id="choose" value = "Enter"> 
   </div>
   </form>
   <?php } 
   formu();

   ?>
   <div id= "here"> </div>
函数形式($w=“1”、$sr=“on”、$comma=“”, $space=“”,$other=“”){?> 选择一个文件 一个
两个

选择选项 切割:


分离器:

sr 逗号 空间 其他(哪个?)
然后我的想法是:

    if($_SERVER["REQUEST_METHOD"] == "POST"){
    $w = $_POST['w'];
    $sr = $_POST['sr'];
    $comma = $_POST['comma'];
    $space = $_POST['space'];
    $other = $_POST['other'];

     if (empty($w) || !($sr || $comma || $space || $other)){
         echo "You have to enter the number and choose at least one separator!";

   } else {
        **/*  here I've tried:
         ?> <script>
         window.location = 'third.php';  //but it doesn't create POST table
         </script> 
         <?php 
         require_once("third.php"); //but it attaches value with reloading the page, so first div shows up above my table
         include "third.php"; //same as above
        */**
 }
 }
if($\u服务器[“请求\u方法”]=“发布”){
$w=$_POST['w'];
$sr=$_POST['sr'];
$comma=$_POST['comma'];
$space=$_POST['space'];
$other=$_POST['other'];
if(空($w)| |!($sr | |$comma | |$space |$other)){
echo“您必须输入数字并至少选择一个分隔符!”;
}否则{
**/*在这里,我试过:
?> 
window.location='third.php';//但它不创建POST表

如果您想按提交按钮,请在javascript中运行
e.preventDefault()
,这将停止表单提交和页面刷新,只运行AJAX调用。@RiggsFolly感谢您的回答,我编辑了我的帖子,因为它不能完全解决我的问题:(尝试
url:$(this.attr('action')!=“”?$(this.attr('action')!=“”?$(this.attr('action')):window.location.pathname,
而不是
url:$(this.attr('action')| | window.location.pathname,
,因为这将返回true或false。F12在浏览器中加载javascript调试器,学会使用它将为您节省数小时的痛苦如果您想按提交按钮,然后在javascript运行
e.preventDefault()
这将停止表单提交和页面刷新,只需运行AJAX调用。@RiggsFolly谢谢您的回答,我编辑了我的帖子,因为它并不能完全解决我的问题:(尝试
url:$(this.attr('action')!=''?$(this.attr('action'):window.location.pathname,
而不是
url:$(this.attr('action'))| | window.location.pathname,
因为这将返回true或false。F12在浏览器中加载javascript调试器,学会使用它,这将为您节省数小时的痛苦
    <script>
    var SubmitBtn2 = document.getElementById('choose');
    SubmitBtn2.onclick = function(){
        var formularz = document.getElementById('sec');
        formularz.style.display = 'none';
        var formularz1 = document.getElementById('first');
        formularz1.style.display = 'none';
        var title2 = document.getElementById('title2');
        $(title2).hide();
        var FormData = {plik: "<?php echo $_POST['radio']; ?>",
                        wiersz: "<?php echo $_POST['w']; ?>",
                        średnik: "<?php echo $_POST['sr']; ?>",
                        przecinek: "<?php echo $_POST['comma']; ?>",
                        spacja: "<?php echo $_POST['space']; ?>",
                        inne: "<?php echo $_POST['other']; ?>",
                        jakie: "<?php echo $_POST['such']; ?>"};
        $(document.getElementById('back')).hide();
        $.ajax({
        type: 'POST',
        url: "third.php",
        data: FormData,
        complete: function (reply) {
            $.ajax({
                type: 'POST',
                url: "third.php",
                complete: function (reply) {
                $('here').append(reply);

                }
            });
    }
  });
    }
    </script>
        $(document.getElementById('choose')).click(function()
        {   event.preventDefault();
                    $.ajax({
                url : $(this).attr('action') || window.location.pathname,
                type: "POST",
                data: $(this).serialize(),
                success: function (data) {
                    $.get("test5new.csv", function(data) {
                var build = '<table border="1" cellpadding="2" cellspacing="0" width="100%">\n';
                var rows = data.split("\n");
                var cut = rows.slice(<?php echo $w; ?>); //ponieważ tablice liczy się od 0 
                cut.forEach( function getvalues(thisRow) {
                    build += "<tr>";
                    var columns = thisRow.split("<?php echo $pattern; ?>");
                    for(var i=0;i<columns.length;i++){ build += "<td>" + columns[i] + "</td>"; }            
                build += "</tr>";
                })
                build += "</table>";
                $(document.getElementById('wrap')).append(build);   

            });
                },
        error: function (jXHR, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });

        });