SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Smola's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy the ajax callback reference...

    Ok I am having issues handling the response of my ajax request. I have two separate script files. One of them is a library I'm building and the other references the specific page I'm working with. I am just trying to get the communication between the client/server working. However, I haven't been able to reference an external callback function for some reason.

    EVERYTHING goes as planned except when I get to the callback reference which I will highlight below. I know this because I debugged with Firebug. All variables are as expected by the time I get to the callback reference.

    un = 'me'
    pw = 'you'

    the html:
    Code html4strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>File Uploader</title>
     
    <script type="text/javascript" src="scripts/smola.js"></script>
    <script type="text/javascript" src="scripts/fileupload.js"></script>
     
    </head>
     
     
    <body>
     
    <div id="login">
    <form>
    	<label for="username">Username:</label>
    	<input type="text" id="username" name="username" maxlength="20" />
    	<br />
    	<label for="password">Password:</label>
    	<input type="password" id="password" name="password" maxlength="20" />
        <br />
        <input type="button" id="submit" value="Login" />
    </form>
    </div>
     
    </body>
    </html>

    The page-specific javascript: fileupload.js
    Code javascript:
    var Files = {
     
    	init: function(){
    		var submitButton = document.getElementById('submit');
    		submitButton.onclick = Files.send;
    	},
     
    	send: function(){
    		var un = document.getElementById('username').value;
    		var pw = document.getElementById('password').value;
    		var url = "fups.php?un="+un+"&pw="+pw;
    		var xmlHttp = Smola.ajaxObj();
    		if (xmlHttp != null) {
    			Smola.ajaxSend(xmlHttp,'GET',url,false,Files.txtResponse);
    		};
    	},
     
    	txtResponse: function(response) {
    		alert(response);
    	}
    };
     
    Smola.start(Files);

    and the Smola library (excerpt, Smola.start runs the init method on window load): smola.js
    Code javascript:
    Smola.ajaxSend = function(ajaxObj, method, url, getXML, callBack) {
    	ajaxObj.onreadystatechange = function() {
            if (ajaxObj.readyState == 4) {
    			if (ajaxObj.status==200 || ajaxObj.status==304) {
                    //request is ready, handle the data based on getXML boolean
                    if (getXML) {
                       callback(ajaxObj.responseXML);
                    }
                    else {
                       callback(ajaxObj.responseText);
                    };
                }
                else {
                    //some error occured, report it somehow
                    alert('error: ' + ajaxObj.status);
                };
             }
             else {
                 //readystate not at 4, maybe display animated progress .gif?
             };
        };
     
    	url = url + "&rand=" + parseInt(Math.random()*99999);
     	ajaxObj.open(method,url,true);
    	ajaxObj.send(null);
    };

    Like I said, everything works. The ajax object is initialized, I can make it to readystate==4, it sees that I choose the responseText, but my callback function won't alert the responseText. And btw, I'm using the GET method.

    oh yea, and here's the fups.php:
    Code php:
    <?php
     
    echo 'un: '.$_GET['un']." pw: ".$_GET['pw'];
     
    ?>

    Any ideas?
    Humbly,

    Smola

  2. #2
    SitePoint Addict Smola's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Crap. What a waste of a post. When I referenced callBack I didn't use a capital B...

    Hope I didn't waste anyone's time too much!
    Humbly,

    Smola


Tags for this Thread

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
  •