简体   繁体   English

在AJAX脚本中传递多个参数

[英]Passing multiple parameters in AJAX script

Below is a script through which I am trying to send two parameters: 'badge' and 'srnum' to name2.php. 下面是一个脚本,我试图通过该脚本将两个参数:'badge'和'srnum'发送到name2.php。

$('input.accept').on('click',function(){

   var badge= $(this).attr('id');
   var srnum = $(this).attr('name');
   //alert(badge+""+srnum);
   $.post('name2.php',{badge:badge,srnum:srnum},function(data){
         $('td#status').text(data);
        });

});

name2.php -: name2.php-:

<?php
  $badge = $_POST['badge'];
  $srnum = $_POST['srnum'];;
  $connection = oci_connect("","","");
  $main_query=oci_parse($connection,"UPDATE LEAVEINFO1 SET LEAD='Approved' WHERE BADGE='$badge' AND SRNUM='$srnum'");
  oci_execute($main_query);
  oci_close($connection);
?>

Now, here I am not able to post 2 variables using the ajax script to name2.php. 现在,在这里我无法使用ajax脚本将2个变量发布到name2.php。 Any help as to how should I post 2 or more variables and receive them in the corresponding name2.php script. 关于如何发布2个或更多变量并在相应的name2.php脚本中接收它们的任何帮助。

You are sending the variables correctly, but not accessing them in php the correct way. 您正在正确发送变量,但没有以正确的方式在php中访问它们。 You can test this by doing var_dump($variable) to be sure you are receiving data. 您可以通过执行var_dump($variable)进行测试以确保您正在接收数据。 Since this is an ajax request, the var_dump results will show in the network tab of the console . 由于这是一个ajax请求,因此var_dump结果将显示在console的“ network选项卡中。

<?php
  $badge = $_POST['badge'];
  $srnum = $_POST['srnum'];
  $connection = oci_connect("","","");
  $main_query=oci_parse($connection,"UPDATE LEAVEINFO1 SET LEAD='Approved' WHERE BADGE='".$badge."' AND SRNUM='".$srnum."'");
  oci_execute($main_query);
  oci_close($connection);
?>

Be sure you are concatenating your strings correctly, using ".$var." 确保使用".$var."正确连接字符串".$var." , with " or ' being the starting quotation. ,以" or '作为起始引号。

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

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