douduocuima61392 2014-04-03 08: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 09: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部