View Full Version : Resolved inconsistent results Ajax Post

01-13-2009, 03:10 PM
1) Script Title: ajaxroutine.js

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm

3) Describe problem: (short version) test case works, production does not.

(long version).
I am building a timelog tool using a mason-enabled, mod-perl server to handle all *.html requests. I want to populate a div on the page with the results from a mason component (for those unfamilar, just think mod-perl script.) using data on the main page as parameters for the component.

function createpoststring(){
var user1 = document.getElementById("user").value;
var date1 = document.getElementById("logdate").value;
var poststr = 'user=' + encodeURI(user1) + '&date=' + encodeURI(date1) ;
return poststr;

//Step 3: Invoke the Ajax routine method to make the desired Ajax request.
function showLog() {
var poststr=createpoststring() //Get contents to post and create query string first
ajaxpack.postAjaxRequest("logentries.html", poststr, processGetPost, "txt")

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")
document.getElementById("logentries").innerHTML = myajax.responseText;


When I use this code without anything else in the page (but a button to make it work) it works just fine. When I add it to my main page and click the button, the ajax doesn't load the div and my current url gets corrupted with the parameter/value pair of another form element named datebox with an encoded version of its contents, e.g. ?datebox=1%2F11%2F2009

So, why is my url changing, and how do I make this work in the context of my main page?

01-13-2009, 04:02 PM
So i got rid of the local url corruption by removing the form wrapper from the button and date field, but I'm still not getting output

01-13-2009, 04:15 PM
I had the wrong div id in my main page. nowhere for the results to go. sorry guys, but thanks anyway.