Ajax ile erişilen php dosyasında formu göndererek?

0 Cevap php

Ben Ajax tarafından erişilen bir sayfada bir formu göndermek için nasıl anlamaya çalışıyorum?

Burada i söylemeye çalışıyorum ne göstermek için bazı kod parçacıkları vardır.

HTML BODY - THIS IS WHAT THE USER WILL SEE.

  <html>
    <head>
     <script language="javascript" src="linktoajaxfile.js">
    </head>
    <body onLoad="gotoPage(0)">
    <div id="fillThis">
    </div>
  </body>
</html>

AJAX FILE

var xmlhttp

function gotoPage(phase)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="pageofstuffce.php";
url=url+"?stg="+phase;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("fillThis").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

PAGE OF DATA

<?php
  $stage = $_GET['stg'];

  if($stage == 0)
  {
     echo '<a onClick="gotoPage(1)">click me</a>';
  }
  elseif($stage == 1)
  {
    <form>
      <input type="text" name="name">
      <input type="submit" name="submit">
    </form>
  }
  elseif(somehow can reach here)
  {
     show data from form.
  }
?>

Can anyone perhaps help me get past the form and display the data in the same page? Also, i have looked around, and i don't think anything around has what i need... correct me if i'm wrong though :)

Thanks in advance, and i hope i didn't put in too much detail :) Dronnoc

EDIT
Forgot to mention what I've tried; I have tried submitting the form to itself (same file) and that destroyed the ajax link, and opened the page. i have also tried just having the button move the page onto another step, but the $_POST variable is empty... i am at a loss, so does anyone else have any ideas?

0 Cevap