【问题标题】:How to send data from a page to another page with ajax如何使用ajax将数据从一个页面发送到另一个页面
【发布时间】:2014-05-15 15:50:48
【问题描述】:

我放了一个循环来获取我数据库的所有值。然后,在每一行的最左边有一个按钮可以打开另一个页面以查看来自特定用户的所有数据库。我的问题是,当您单击我的按钮时,会出现一个函数(函数 ouvrirEditFormulaire),而我要做的是获取 4 个值并将其发送到该页面:acceptation.php。因此,在我的函数中,我打开了一个新窗口,然后使用 ajax 将我的数据发送到 eFormulaire.php,然后我尝试在我的另一个页面(acceptation.php)中对一个 div 进行内部 HTML,但没有任何反应。我能做的最多就是在我的第一页内插入一个 div(当你点击按钮时)......有没有办法将数据发送到我的 acceptation.php ???

我的 AJAX:

function ouvrirEditFormulaire(id,date,heure,client) {
    window.open('concessionnaire/acceptation.php','mywin','left=20,top=20,width=650,height=730');
    var xhr = new XMLHttpRequest();
    xhr.open("POST","concessionnaire/eFormulaire.php",true);
    xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4 && xhr.status == 200) {
               document.getElementById('divAnotherPage').innerHTML = xhr.responseText;
        }
    }
    xhr.send("id="+id+"&date="+date+"&heure="+heure+"&client="+client);
}

eFormulaire.php:

<?php
include_once('../connect.php');
$object = new User;
$id = $_POST['id'];
$date = $_POST['date'];
$heure = $_POST['heure'];
$client = $_POST['client'];
?>

【问题讨论】:

  • 它看起来不像 ajax 对我来说

标签: php ajax database


【解决方案1】:

您不需要 AJAX:

function ouvrirEditFormulaire(id,date,heure,client) { 
    var url = 'concessionnaire/acceptation.php';     
    window.open(url + "?id="+id+"&date="+date+"&heure="+heure+"&client="+client, 'mywin','left=20,top=20,width=650,height=730');
}

现在您正在打开一个不带参数的新页面,然后在不同的请求中发布到同一页面

您还必须有机会在 acceptation.php 上$_GET[xxx]

如果您想在当前页面上打开 acceptation.php 并在某种对话框 div 中显示结果,则 AJAX 调用可能会很方便。

【讨论】:

  • 太好了,谢谢老金。它对我帮助很大!也感谢您的解释:)
猜你喜欢
  • 2012-12-21
  • 2020-08-16
  • 2013-01-24
  • 2017-05-22
  • 2016-03-19
  • 1970-01-01
  • 2022-06-17
  • 1970-01-01
  • 2023-03-24
相关资源
最近更新 更多