...

View Full Version : problem during update



carlitos_way
03-12-2007, 06:57 PM
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):



<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:


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 ;)

A1ien51
03-13-2007, 04:13 PM
Why don't you send something back in the response like Update~Successful.

than check for it when the data comes back


result = http_request.responseText;

if(result.indexOf("Update~Successful") == -1)
document.getElementById('target').innerHTML = result;


Another thing is to learn about OO JavaScript

Eric

carlitos_way
03-14-2007, 12:31 PM
thank you, i'll follow your suggestion, and also try to learn something about OO Js! ;)

SSJ
03-14-2007, 01:29 PM
OO JavaScript will be helpful to you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum