gpt4 book ai didi

php - 使用 AJAX 发送变量到 2 个 php 页面

转载 作者:行者123 更新时间:2023-12-01 04:49:26 25 4
gpt4 key购买 nike

我有一个关于通过 AJAX 发送变量到 2 个外部 php 页面的问题,所以我在 fab.php 中有一个变量,它将在 data2.php 中使用,并且data3.php

所以fab.php中的ajax是这样的

$(function(){
// SHOW RECORD
$('#show').click(function(){
$.post('data2.php',
{action: "show",
"hm":$('#headmark').val()},
function(res){
$('#result').html(res);
});
});
});

我成功地能够在data2.php中使用“hm”与此

if($_POST['action'] == 'show'){


$sql = "SELECT * FROM SUB_MASTER_DRAWING
// "hm" is passed from the previous page
WHERE SUB_MASTER_DRAWING.HEAD_MARK = '{$_POST["hm"]}'";

在此页面中应显示与“hm”值对应的结果,用户可以直接更新它并将更新后的值发送回data3.php中的服务器为了更新它,我仍然需要在 data3.php 中选择进行更新过程的“hm”值

我尝试了这个方法,但不起作用

 $(function(){
// SHOW RECORD
$('#show').click(function(){
$.post('data2.php', 'data3.php',
{action: "show",
"hm":$('#headmark').val()},
function(res){
$('#result').html(res);
});
});
});

最佳答案

首先使用 SESSION 将您的 $.ajax 请求发送到 data2.php

在data2.php

     <?php
session_start(); #start session here

#declare session varible and assign POST value to session
$_SESSION['getvalue'] = $_POST['getValue'];

在data3.php中

 <?php
session_start(); #start session here

#And use $_SESSION['getvalue'] now

关于php - 使用 AJAX 发送变量到 2 个 php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23003131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com