# Post/get through ajax troubles

**URL:** <https://forum.kirupa.com/t/post-get-through-ajax-troubles/250486>\
**Category:** Uncategorized\
**Created:** [January 29, 2008, 11:31pm UTC](https://forum.kirupa.com/t/post-get-through-ajax-troubles/250486 "2008-01-29T23:31:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlk](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mlk](https://forum.kirupa.com/u/mlk)\
**Post date:** [January 29, 2008, 11:31pm UTC](https://forum.kirupa.com/t/post-get-through-ajax-troubles/250486/1 "2008-01-29T23:31:32Z")

</div>

hey there kirupa gang, i have little troubles with a simple site; here’s the diagram:

![](http://forum.kirupa.com/uploads/kirupa/4275/b8ffabfd0fcff81d.jpg)

Contents are placed in a div thru ajax; it works perfectly and parses php right but here’s the catch, how do I use post and get with that div ?

**I use a standard contact.php page:**  
-php checks if there’s anything in ‘post’ (and validates) and  
-php displays a #mail sent# form if mailto() was success  
or  
-php displays a form to send a message which uses a ‘post’ action to itself (contact.php)

**Here’s the catch:**  
Since I load contact.php in the div thru ajax/dhtml I can’t use standard ‘submit’ button or it refreshes the page with post but I have to use my ajax code. Now how do I transmit post ? (or get for that matter). It seems that my contact.php page gets its ‘post’ from the root (index.php)

have I lost everyone ?

I use the following xmlhttprequest:

```auto

function fetch(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {fetchDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function fetchDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML="Page Error:
"+ req.status + "
" +req.statusText;
    }
  }
}

function loadthis(name, div) {
	fetch(name,div);
	return false;
}

```

thanks to anyone who attempts to understand me :pleased:
