douduocuima61392 2014-04-03 16:48
浏览 226
已采纳

如何使用ajax将数据从页面发送到另一个页面

I put a loop to get all my values of my database. Then, at the very left of each row there's a button to open another page to see all the database from a specific user. My problem here is that when you click on my button, there's a function that appears (function ouvrirEditFormulaire) and what I am trying to do is to get 4 values and to send it to that page : acceptation.php. So in my function I open a new window, then with ajax send my data to eFormulaire.php and I tried to innerHTML a div inside my other page (acceptation.php) but nothing happens. The most I could do is to innerHTML a div inside my first page (when you click on the button)...is there any way to send data to my acceptation.php ???

My 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'];
?>
  • 写回答

1条回答 默认 最新

  • douyu0792 2014-04-03 17:19
    关注

    You don't need AJAX for this:

    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');
    }
    

    Right now you are opening a new page without parameters and then posting to the same page in a different request.

    You will also have to chance to $_GET[xxx] on acceptation.php.

    The AJAX call could be handy if you wanted to open the acceptation.php while remaining on the current page and show the results in some sort of dialog div.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思