Hi:
I see several errors on your page as far as how you're invoking the ajax routine. Here is the relevant portion of your page:
Code:
<script type="text/javascript">
function createpoststring(){
var namevalue=document.getElementById("relatives").innerHTML //get value to post from a DIV
var agevalue=document.getElementById("myform").agefield.value //get value to post from a form field
var poststr = "name=" + encodeURI(namevalue) + "&age=" + encodeURI(agevalue)
return poststr
}
//Step 3: Invoke the Ajax routine method to make the desired Ajax request.
var poststr=createpoststring() //Get contents to post and create query string first
ajaxpack.postAjaxRequest("postit.php", poststr, processGetPost, "txt")
</script>
<a href="#" onclick="var poststr=createpoststring(); ajaxpack.postAjaxRequest('ajaxfiles/postit.php', poststr, processGetPost, 'txt'); return false">
Run example</a> | Source for <a target="eg" href="ajaxfiles/postit.php.txt">
postit.php</a>
It's hard to articulate all the errors above, but the correct version should look something like:
Code:
<script type="text/javascript">
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}
function createpoststring(){
var namevalue=document.getElementById("relatives").innerHTML //get value to post from a DIV
var agevalue=document.getElementById("myform").agefield.value //get value to post from a form field
var poststr = "name=" + encodeURI(namevalue) + "&age=" + encodeURI(agevalue)
return poststr
}
var poststr=createpoststring() //Get contents to post and create query string first
</script>
<a href="#" onClick="ajaxpack.postAjaxRequest("postit.php", poststr, processGetPost, "txt"); return false">
Run example</a> | Source for <a target="eg" href="ajaxfiles/postit.php.txt">
postit.php</a>
As you can see, your code is missing a function, plus is invoking the onClick= portion incorrectly inside the link.
Bookmarks