Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    italy
    Posts
    94
    Thanks
    1
    Thanked 1 Time in 1 Post

    Lightbulb problem during update

    hi all, i started my learning in ajax doing a web application that emulates a sort of spreadsheet (similar to excel).
    so i have a jsp page that through ajax calls the server making a SELECT and display a table full of input texts (something similar to this):

    Code:
    <tr>
    						  <td>
    							  <input type="text" value="<klds:getString column='CODFORN' />" 
    							   class="readonly"
    							   >
    						  </td> 
    						  <td>
    							  <input type="text" value="<klds:getString column='DENOMINAZIONE' />" 
    							   id="<klds:getString column='CODFORN' />" class="editable closed"
    							   onClick="onClick('<klds:getString column='CODFORN' />');"
    							   onDblClick="dblClick('<klds:getString column='CODFORN' />');"
    							   onChange="onChange('<klds:getString column='CODFORN' />');"					   
    							   onBlur="onBlur('<klds:getString column='CODFORN' />');"					   
    							   >
    						  </td>
    					  </tr>
    when i see a change on a field, i call the update function (always using jsp).
    this is the ajax code i'm using:
    Code:
    var http_request = false;
    
    function makePOSTRequest(url, parameters) {
    	http_request = false;
    
    	if (window.XMLHttpRequest) { // Mozilla, Safari,...
    		http_request = new XMLHttpRequest();
    		if (http_request.overrideMimeType) {
    			// set type accordingly to anticipated content type
    			//http_request.overrideMimeType('text/xml');
    			http_request.overrideMimeType('text/html');
    		}
    	} else if (window.ActiveXObject) { // IE
    		try {
    			http_request = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try {
    			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e) {}
    		}
    	}
    
    	if (!http_request) {
    		alert('Cannot create XMLHTTP instance');
    		return false;
    	}
    	
    	http_request.onreadystatechange = alertContents;
    	http_request.open('POST', url, true);
    	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	http_request.setRequestHeader("Content-length", parameters.length);
    	http_request.setRequestHeader("Connection", "close");
    	http_request.send(parameters);
    	return false;
    }
    
    function alertContents() {
    	if (http_request.readyState == 4) {
    		if (http_request.status == 200) {
    			result = http_request.responseText;
    			document.getElementById('target').innerHTML = result;
    		} 
    		else {
    			alert('Attenzione, è stato riscontrato un problema dal server.');
    		}
    	}
    }
    now, the problem comes in the alertContents function: as during the update i just send informations to the server and don't receive anything as a result, i don't want the line
    document.getElementById('target').innerHTML = result;
    to be executed, because it replaces the page with just anything and so doesn't show the table anymore.

    i tried with a global variable as a flag, but it doesn't work. i also tried passing a parameter but nothing seems to happen.. (the problem is caused by my short experience in js)

    what can i do?

    thanks

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Why don't you send something back in the response like Update~Successful.

    than check for it when the data comes back
    Code:
    result = http_request.responseText;
    
    if(result.indexOf("Update~Successful") == -1)
      document.getElementById('target').innerHTML = result;
    Another thing is to learn about OO JavaScript

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    italy
    Posts
    94
    Thanks
    1
    Thanked 1 Time in 1 Post
    thank you, i'll follow your suggestion, and also try to learn something about OO Js!

  • #4
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    OO JavaScript will be helpful to you


  •  

    Posting Permissions

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