Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-12-2007, 05:57 PM   PM User | #1
carlitos_way
New Coder

 
Join Date: Mar 2007
Location: italy
Posts: 94
Thanks: 1
Thanked 1 Time in 1 Post
carlitos_way is an unknown quantity at this point
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
carlitos_way is offline   Reply With Quote
Old 03-13-2007, 03:13 PM   PM User | #2
A1ien51
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
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Old 03-14-2007, 11:31 AM   PM User | #3
carlitos_way
New Coder

 
Join Date: Mar 2007
Location: italy
Posts: 94
Thanks: 1
Thanked 1 Time in 1 Post
carlitos_way is an unknown quantity at this point
thank you, i'll follow your suggestion, and also try to learn something about OO Js!
carlitos_way is offline   Reply With Quote
Old 03-14-2007, 12:29 PM   PM User | #4
SSJ
Regular Coder

 
Join Date: Mar 2007
Posts: 230
Thanks: 0
Thanked 4 Times in 4 Posts
SSJ is an unknown quantity at this point
OO JavaScript will be helpful to you
__________________
Best Joomla Design Agency India ||PSD to Joomla Template || Award Winning Web Design Company India
SSJ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:33 AM.


Advertisement
Log in to turn off these ads.