I've been following a tutorial that describes 'Hijax' from the book Bulletproof Ajax and it is not that clear exactly where the sections of code go...can anyone please help with this and troubleshoot??
(I am a complete novice with this and it's taken me ages to type it all out!!) Help appreciated,
Many thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="ajax.js"></script>
<title>Contact Us</title>

<h1>Contact Us</h1>
<div id="container">
<?php include "formlogic.php";?>

Formlogic.php is....

<form method="post" id ="contactform" action="">
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" />
<label for="message">Message</label>
<textarea name="message" id="message" cols="30" rows="10">
<input type="submit" name="submit" value="Submit" />

And ajax.js is...

function sendData(data) {
 var request = getHTTPObject();
 if (request) {
  request.onreadystatechange = function() {
  request.open( "POST", "formlogic.php", true);
  return true;
  } else {
  return false;
 window.onload = prepareForm;
 function prepareFrom() {
 if(!document.getElementById) {
 if(!document.getElementById("contactform")) {
 document.getElementById("contactform").onsubmit =
 function() {
 var data=" ";
 for(var i=0; i<this.elements.length; i++) {
 data+= this.elements[i].name;
 data+= "=";
 data+= escape(this.elements[i].value);
 data+= "&";
 return !sendData(data);
 function parseResponse(request) {
 if (request.readyState == 4) {
 if (request.status == 200 || request.status == 304) {
 var container = document.getElementById("container");
 container.innerHTML = request.responseText;

Why do you have AJAX send the data to the formlogic.php script?

You need to have a script that can process the data you are sending, and have AJAX send the data there.

thanks for the response...eventually I found the code online http://www.bulletproofajax.com/code/

The chapter in the book was called Hijax - using javascript,php, html....I'm not sure what exactly the javascript does, seems to process the form.



This article has been dead for over six months. Start a new discussion instead.