Results 1 to 4 of 4
  1.    #1  
    Help! I'm an undergrad student developing an app for my senior thesis. I want the app to pull data from a database that is stored on my computer. I created an access database and I also created an asp page to display the info. I used an http request to get the data, but I don't know how to manipulate the data.

    Code:
    WelcomeAssistant.prototype.login = function(event){
    	this.controller.get('BrowserTextField').update(this.txtModel['originalValue']);
    	this.controller.get('PasswordTextField').update(this.passModel['original']);
    	var url ="http: //.. .//test/login. asp? first_name="+this.txtModel['originalValue']+"&password="+this.passModel['original'];
    	
    	makeRequest(url);
    };
    
    var http_request = false; 
    
    function makeRequest(url) {
    
      if (window.XMLHttpRequest) { // Mozilla, Safari, IE7... 
          http_request = new XMLHttpRequest();
      } else if (window.ActiveXObject) { // IE6 and older 
          http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      http_request.onreadystatechange = alertContents; 
      http_request.open('GET', url, false); 
      http_request.send(null); 
    
    this.controller.stageController.pushScene('logged', url);
    } 
    
    function alertContents() { 
      if (http_request.readyState == 4) { 
          if (http_request.status == 200) { 
    	 	 Mojo.Controller.errorDialog(http_request.responseText); 
          } else { 
              Mojo.Controller.errorDialog("There was a problem with the request."); 
          } 
      } 
    }
  2. #2  
    Quote Originally Posted by anuthaone View Post
    Help! I'm an undergrad student developing an app for my senior thesis. I want the app to pull data from a database that is stored on my computer. I created an access database and I also created an asp page to display the info. I used an http request to get the data, but I don't know how to manipulate the data.

    Code:
    WelcomeAssistant.prototype.login = function(event){
    	this.controller.get('BrowserTextField').update(this.txtModel['originalValue']);
    	this.controller.get('PasswordTextField').update(this.passModel['original']);
    	var url ="http: //.. .//test/login. asp? first_name="+this.txtModel['originalValue']+"&password="+this.passModel['original'];
    	
    	makeRequest(url);
    };
    
    var http_request = false; 
    
    function makeRequest(url) {
    
      if (window.XMLHttpRequest) { // Mozilla, Safari, IE7... 
          http_request = new XMLHttpRequest();
      } else if (window.ActiveXObject) { // IE6 and older 
          http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      http_request.onreadystatechange = alertContents; 
      http_request.open('GET', url, false); 
      http_request.send(null); 
    
    this.controller.stageController.pushScene('logged', url);
    } 
    
    function alertContents() { 
      if (http_request.readyState == 4) { 
          if (http_request.status == 200) { 
    	 	 Mojo.Controller.errorDialog(http_request.responseText); 
          } else { 
              Mojo.Controller.errorDialog("There was a problem with the request."); 
          } 
      } 
    }
    Firstly, use the Prototype.Ajax() function. It is official will definitely work.

    Secondly, make sure your ASP page outputs the database info in JSON.

    Thirdly, read up on JSON and how to parse within JavaScript and then you will be in business. W3C is a good place to start.
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  3. #3  
    What arthurthornton said! I use PHP/MySQL to do the exact same thing. The code on the webOS side is identical. I posted an example here.
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  4.    #4  
    Thanks so much for your responses. I was able to output the database info to JSON but after that I am running into more problems. I also switched to the Ajax.prototype function as you suggested, but I am experiencing strange results, nothing happens when I attempt to login.

    I can not figure out how to successfully parse my JSON in javascript. Here is what I have up to this point:

    Code:
    if (this.txtModel['originalValue'] == '' || this.passModel['original'] == '') {
    	Mojo.Controller.errorDialog('Please enter both your Username and Password!', this.controller.window);
    	this.controller.get('login').mojo.deactivate();
    }
    else {
    	var loginAjaxURL = "htt p://.. /test/login. asp ? first_name=" + this.txtModel['originalValue'] + "&password=" + this.passModel['original'];
    	
    	var request = new Ajax.Request(loginAjaxURL, {
    		method: 'post',
    		evalJSON: 'force',
    		onSuccess: this.loginAjaxSuccess.bind(this),
    		onFailure: this.loginAjaxFailure.bind(this)
    	});
    	
    	var loginAjax = new Ajax.Request(loginAjaxURL, loginAjaxAttributes);
    }
    	
    };
    
    WelcomeAssistant.prototype.loginAjaxSuccess = function(response){
    	// GET DATA FROM JSON RESPONSE
        // TAKE ACTION BASED ON THE RESPONSE "STATUS"
    Mojo.Controller.errorDialog("Came here");
            var response = response.responseText.evalJSON(true);
    		Mojo.Controller.errorDialog("Hello"+response);
    /*
            if (typeof(response.id) == 'undefined')
    		 {Mojo.Controller.errorDialog('There was an error logging into your account, please check your ionternet connection try again!', this.controller.window); this.controller.get('login').mojo.deactivate();}
            else
            {
                // SET LOCAL VARIABLES
                // DEACTIVATE BUTTON
                // PUSH NEXT SCENE BASED ON USER TYPE
    
                    var userID        = response.ID;
                    var userFirstName = response.FIRST_NAME;
                    var userLastName  = response.LAST_NAME;
    
                    this.controller.get('login').mojo.deactivate();
                    this.controller.stageController.pushScene('logged');}
                 */  
            }
    Note: I attempt to display an errorDialog to see if my code is reaching loginAjaxSuccess, but it doesn't do anything. I'm sure this is something very simple but I'm making it more complicated than it has to be. Thanks again for your help.

Posting Permissions