简体   繁体   English

如何在JavaScript中发布多个变量?

[英]How post more than one variable in javascript?

There is 2 input type="text". 有2个输入type =“ text”。 First, user input 1st input text area with id="ncr_no". 首先,用户输入的第一个输入文本区域的ID =“ ncr_no”。 Then, cursor is in 2nd input type "text" with id="itm_cd". 然后,光标位于id =“ itm_cd”的第二个输入类型“ text”中。 Now, I want to make, how the two input by user, when cursor is in 2nd input type, posted to other php (get_ncrnoitmcd.php) by javascript? 现在,我要制作的是当光标处于第二输入类型时,用户的两个输入如何通过javascript发布到其他php(get_ncrnoitmcd.php)? That's the code. 那就是代码。

<script type="text/javascript">
    $(document).ready(function() {
        $("#itm_cd").keyup(function (e) {
            $(this).val($(this).val().replace(/\s/g, ''));

            var itm_cd = $(this).val();

            if(itm_cd.length < 1){$("#user-result3").html('');return;}

            if(itm_cd.length >= 1 ){
                $("#user-result3").html('<img src="image/ajax-loader.gif" />');
                $.post('get_ncrnoitmcd.php', {'itm_cd':itm_cd},  function(data) {
                  $("#user-result3").html(data);
                });
            }
        }); 
    });
</script>

Thank a lot. 非常感谢。

This is the way you can send the 2 values to server on 2nd element keyup after validation. 这样,您便可以在验证后将2个值发送到第二个元素keyup上的服务器。 Whats the problem that you are facing? 您面临的问题是什么? I also added ncr_no in the post request. 我还在发布请求中添加了ncr_no。

<script type="text/javascript">
        $(document).ready(function() {
            $("#itm_cd").keyup(function (e) {
                $(this).val($(this).val().replace(/\s/g, ''));
                var itm_cd = $(this).val();
                if(itm_cd.length < 1){
                    $("#user-result3").html('');
                    return;
                }else if(itm_cd.length >= 1 ){
                    $("#user-result3").html('<img src="image/ajax-loader.gif" />');
                    $.post(
                        'get_ncrnoitmcd.php'
                       ,{'itm_cd':itm_cd,'ncr_no':$('#ncr_no').val()}
                       ,function(data) {
                           $("#user-result3").html(data);
                       }
                    );
                }
            }); 
        });
</script>

I want to get available or not available, Mr. @joyBlanks 我想上班还是不上班,@ joyBlanks先生

<?php
//connection.php

if(isset($_POST["itm_cd"],$_POST["ncr_no"]))
{
    if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
        die();
    }

    $connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
    $itm_cd =  strtolower(trim($_POST["itm_cd"])); 
    $itm_cd = filter_var($itm_cd, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
    $results = mysqli_query($connecDB,"SELECT itm_cd,ncr_no FROM sqc_ncr WHERE itm_cd ='$itm_cd' AND ncr_no ='$ncr_no'");
    $itm_cd_exist = mysqli_num_rows($results); 
    if($itm_cd_exist) {
        die('<!--img src="image/available.png" /--> <i>Available in database</i>');
    }else{
        die('<!--img src="image/not-available.png" /--> <i>Not Available in database</i>');
    }
    mysqli_close($connecDB);
}
?>

我没有使用过,也没有使用过&&,也没有使用过http_x_requested,但是在未显示的html中可用或不可用。

<td><input type="text" class="input" name="itm_cd" id="itm_cd"  onBlur="updateItemName()" required /> <span id="user-result3"></span></td>

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

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