AJAX Problem

R

Ravi

in my script i declared one variable as global.I am tying to acess it
in a function but it is not comming in Mozilla . it is executing in
ie.

My code is

var http = createRequestObject();
function createRow(key,val,tableId,index,numele,evt)
{
var table = document.getElementById(tableId);
var newRowFlag = false;
evt = (evt) ? evt : window.event
var charCode = (evt.which) ? evt.which : evt.keyCode
switch(charCode)
{
case 13 :
case 9 : if(parseInt(table.rows.length) ==
(parseInt(index)))
newRowFlag=true;
}
if(newRowFlag)
{
http.open('get',"gridClass.php?rowkey="+key
+"&rowval="+val
+"&index="+index+"&tabid="+tableId);
http.onreadystatechange = function(){

insertRow(tableId,index,numele);};
http.send(null);
}

}

function insertRow(tableId,index,numele)
{
alert(http.readystate);
if(http.readystate == '4')
{
var response = http.responseText;
var table = document.getElementById(tableId);
var td = response.split('^');
newRow = table.insertRow();
for(i=0;i<numele;i++)
{
isText = newRow.insertCell(i);
isText.innerHTML = td;
}
}

}

Thanks in advance
Ravindra
 
D

Darko

in my script i declared one variable as global.I am tying to acess it
in a function but it is not comming in Mozilla . it is executing in
ie.

My code is

var http = createRequestObject();
function createRow(key,val,tableId,index,numele,evt)
{
var table = document.getElementById(tableId);
var newRowFlag = false;
evt = (evt) ? evt : window.event
var charCode = (evt.which) ? evt.which : evt.keyCode
switch(charCode)
{
case 13 :
case 9 : if(parseInt(table.rows.length) ==
(parseInt(index)))
newRowFlag=true;
}
if(newRowFlag)
{
http.open('get',"gridClass.php?rowkey="+key
+"&rowval="+val
+"&index="+index+"&tabid="+tableId);
http.onreadystatechange = function(){

insertRow(tableId,index,numele);};
http.send(null);
}

}

function insertRow(tableId,index,numele)
{
alert(http.readystate);
if(http.readystate == '4')
{
var response = http.responseText;
var table = document.getElementById(tableId);
var td = response.split('^');
newRow = table.insertRow();
for(i=0;i<numele;i++)
{
isText = newRow.insertCell(i);
isText.innerHTML = td;
}
}

}

Thanks in advance
Ravindra


The most important thing that you didn't show is what the
createRequestObject() function does. That's probably the reason for
your problems, because you've probably written it as such to conform
only to IE "standards" (notice the quotes).
 
R

Ravi

in my script i declared one variable as global.I am tying to acess it
in a function but it is not comming in Mozilla . it is executing in
ie.
My code is
var http = createRequestObject();
function createRow(key,val,tableId,index,numele,evt)
{
var table = document.getElementById(tableId);
var newRowFlag = false;
evt = (evt) ? evt : window.event
var charCode = (evt.which) ? evt.which : evt.keyCode
switch(charCode)
{
case 13 :
case 9 : if(parseInt(table.rows.length) ==
(parseInt(index)))
newRowFlag=true;
}
if(newRowFlag)
{
http.open('get',"gridClass.php?rowkey="+key
+"&rowval="+val
+"&index="+index+"&tabid="+tableId);
http.onreadystatechange = function(){
insertRow(tableId,index,numele);};
http.send(null);
}

function insertRow(tableId,index,numele)
{
alert(http.readystate);
if(http.readystate == '4')
{
var response = http.responseText;
var table = document.getElementById(tableId);
var td = response.split('^');
newRow = table.insertRow();
for(i=0;i<numele;i++)
{
isText = newRow.insertCell(i);
isText.innerHTML = td;
}
}

Thanks in advance
Ravindra


The most important thing that you didn't show is what the
createRequestObject() function does. That's probably the reason for
your problems, because you've probably written it as such to conform
only to IE "standards" (notice the quotes).





function createRequestObject() {
var tmp;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
tmp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
tmp = new XMLHttpRequest();
}
return tmp;
}


This is the function my problem is in insertRow function http variable
is becomming local.It is not giving any response.
 
L

-Lost

Ravi said:
function createRequestObject() {
var tmp;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
tmp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
tmp = new XMLHttpRequest();
}
return tmp;
}


This is the function my problem is in insertRow function http variable
is becomming local.It is not giving any response.

Your problem is using horribly written browser sniffing code. Try
feature detecting and definitely take a look at:

http://jibbering.com/faq/index.html#FAQ4_44

Granted, this is not your entire solution. It is merely a starting point.
 
D

Darko

<snip code>






Your problem is using horribly written browser sniffing code. Try
feature detecting and definitely take a look at:

http://jibbering.com/faq/index.html#FAQ4_44

Granted, this is not your entire solution. It is merely a starting point.

OK, it's true what Lost said, but it's not the reason for your errors.
It's some stupid syntax errors that you've made, that took me a while
to notice. First, in the open() call, you have to pass "true" as the
last argument (which you didn't do), that says you want asynchronous i/
o (as almost all ajax programmers do). The second thing, you don't
check for http.readystate, but http.readyState (capital 'S') -
Javascript is case-sensitive. Third, what Lost said, you've got much
too simple getAjax-function, take a look at the following (which I
use), it might be of help:
function getAJAXHandler()
{
var http = null;
try {
if (window.XMLHttpRequest) // Mozilla, Safari,...
http = new XMLHttpRequest();
else if (window.ActiveXObject) { // IE
try {
http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
} catch ( e ) {}
return http;
}
If you get null for this function, that means the browser you have
either doesn't support ajax or isn't handled well by the function. But
should work well.
 
R

Ravi

Thanks Darko but tell me one thing why it is executing in IE if
javascript is case sensitive then it should not work in IE also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top