简体   繁体   English

重定向到新的jquery验证通过页面

[英]redirect to new page of jquery validation passes

I have a jquery something like 我有一个类似的jQuery

$(document).ready(function() {
    $('#value').change(function() {
        $.ajax({
            type:'POST',
            url:'../validation.php',
            data: {
                validate_year:$('#Year').val(),
                validate_value:$('#value').val(),
                validate_domain:$('#Domain').val(),
            },
            success: function (data) {

            }
        })
    });
});

in validation.php I have a sql statement which basically uses whatever is in Year , value and domain and then runs a select statement and the result is then rendering into a table in the same validation.php using echo $something in the table <tr> . validation.php我有一条sql语句,该语句基本上使用Yearvaluedomain任何value ,然后运行select语句,然后将结果使用表<tr>中的echo $something呈现到同一validation.php中的表中。 <tr> What I want to do this display the validation.php to the user so the can see this table... because so they can make changes to it such as update and delete. 我要执行的操作向用户显示了validation.php ,因此可以看到此表...,因为这样他们可以对其进行更改,例如更新和删除。

How can I do this? 我怎样才能做到这一点?

Could try something like this 可以尝试这样的事情

$(document).on('change', '#value', function() {
    $.post('/validation.php', {validate_year:$("#Year").val(), 
         validate_value:$("#value").val(), 
         validate_domain$("#Domain").val()}, function(data) {
       //Take the output of validation.php and put them into a class or id target
       $(".target-area").html(data);
  }
});

Basically what is happening is that the $.post function is reaching out to a URL that you specify, in this case validation.php. 基本上发生的是$ .post函数正在连接到您指定的URL,在本例中为validation.php。 I am guessing that you are trying to return something to the javascript file that indicates whether something is valid or not. 我猜您正在尝试将某些内容返回到javascript文件,以指示某些内容是否有效。 So for example 所以举个例子

//valiation.php
<?php
$validate_year = $_POST['validate_year'];
$validate_value = $_POST['validate_value'];
$validate_domain = $_POST['validate_domain'];

//Do something here to determine if it is valid or not

//If the result is $valid in this pseudo code example
if($valid) {
   echo 'true';
} else {
   echo 'false';
}

In this example, the PHP script is returning a value of true or false based on the checks that you made against a database, expected results, etc, etc to the posted variable, in this case it is returned as the data variable in javascript. 在此示例中,PHP脚本基于对发布的变量对数据库所做的检查,预期的结果等,返回true或false的值,在这种情况下,它作为javascript中的data变量返回。

So if you did something like this, 所以如果你做了这样的事情,

$(document).on('change', '#value', function() {
        $.post('/validation.php', {validate_year:$("#Year").val(), 
             validate_value:$("#value").val(), 
             validate_domain$("#Domain").val()}, function(data) {
           //Take the output of validation.php and log it to the console
           console.log(data);
      }
    });

You would see the true or false result from the validation.php file I wrote. 您会从我编写的validation.php文件中看到truefalse结果。 You probably want to return something to notify the user whether or not the validation failed or succeeded. 您可能想返回一些东西来通知用户验证是否成功。 So to expand on this, say you had a div on your page setup like this 因此,要对此进行扩展,请说您在页面设置上有一个div这样的

<div id="validation-result"></div>

Your javscript would interpret the response from validation.php and output something to the user ... like this 您的javscript会解释来自validation.php的响应,并向用户输出一些信息……

   $(document).on('change', '#value', function() {
            $.post('/validation.php', {validate_year:$("#Year").val(), 
                 validate_value:$("#value").val(), 
                 validate_domain$("#Domain").val()}, function(data) {
               //Take the output of validation.php, parse it and update the page
               if(data == 'true') {
                  var content = "Your validation succeeded";
               } else {
                  var content ="Your validation failed";
               }
               $("#validation-result").html(content);
          }
        });

And the final result on your page would look like this for true 您页面上的最终结果看起来像这样

<div id="validation-result">Your validation succeeded</div>

or this for false 或者这是假的

<div id="validation-result">Your validaiton failed</div>

Hope that help clears up the answer a little bit for you 希望有帮助为您澄清答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM