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

如何使用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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题