Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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 如何使用POST方法通过Ajax发送2个表单值_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 如何使用POST方法通过Ajax发送2个表单值

Javascript 如何使用POST方法通过Ajax发送2个表单值,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,如何使用POST方法通过Ajax将表单(A和B)的2个值发送到check.php 在下面的源代码中,我能够向check.php发送2个输入值,并将2个值放入变量$A和$B中,然后返回答案。但是我不想刷新页面。为此,我想从AJAX获得帮助。有人能为我写AJAX代码吗?(将两者发送到check.php并以AJAX形式接收响应) 投票 checker.php if($result2->execute()) { $msg[status]='success'; echo j

如何使用POST方法通过Ajax将表单(A和B)的2个值发送到check.php


在下面的源代码中,我能够向check.php发送2个输入值,并将2个值放入变量$A和$B中,然后返回答案。但是我不想刷新页面。为此,我想从AJAX获得帮助。有人能为我写AJAX代码吗?(将两者发送到check.php并以AJAX形式接收响应)


投票
checker.php

 if($result2->execute())
    {
$msg[status]='success';
       echo json_encode($msg);
        exit;
    }
    else
    {
$msg[status]='error';
 echo json_encode($msg);
        exit;
    }

您可以使用Ajax进行操作,并稍微修改checker.php以与回调操作的Ajax请求相匹配。

@tom udding您能帮我吗?“有人能为它编写Ajax代码吗?”没有-但是您可以先尝试创建一些东西,看看您能走多远,如果您陷入困境,社区将帮助您走出困境。请在此处查看入门指南:
<?php
include "connection.php";
$i=0;
$sql="select * from Poll";
$result=$connect->query($sql);
$A=$_POST["framework1"];
$B=$_POST["framework2"];

foreach($result as $rows)
{
    if($rows["ip"]==$_SERVER["REMOTE_ADDR"])
        $i=$i+1;
}
if($i>=1)
{
    header("location:index.php?cancell=1010");
    exit;
}
else
{
    $sql2="INSERT INTO `whoftwho_Poll`.`Poll` (`id` ,`answer` ,`ip`)VALUES (NULL , ?, ?);";
    $result2=$connect->prepare($sql2);
    $result2->bindValue(1,$_POST["framework1"]);
    $result2->bindValue(2,$_SERVER["REMOTE_ADDR"]);
    if($result2->execute())
    {
        header("location:index.php?insert=1010");
        exit;
    }
    else
    {
        header("location:index.php?error=1010");
        exit;
    }
}
?>
$.ajax({
  method: "POST",
  url: "check.php",
  data: $('#Poll').serialize
})
  .done(function( msg ) {
if (msg.status=='success'){
alert('member check pass');
}else{
alert('member check failed');
}
  });
 if($result2->execute())
    {
$msg[status]='success';
       echo json_encode($msg);
        exit;
    }
    else
    {
$msg[status]='error';
 echo json_encode($msg);
        exit;
    }