Results 1 to 3 of 3

Thread: inconsistent results Ajax Post

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question inconsistent results Ajax Post

    1) Script Title: ajaxroutine.js

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxroutine.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.

    Code:
    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;
    			else
    				alert(myajax.responseXML)
    			
    		} 
    	} 
    }
    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?

  2. #2
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  3. #3
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy i'm an idiot

    I had the wrong div id in my main page. nowhere for the results to go. sorry guys, but thanks anyway.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •