469,315 Members | 1,448 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

AJAX Problem

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[i];
}
}

}

Thanks in advance
Ravindra

May 24 '07 #1
5 1999
On May 24, 3:16 pm, Ravi <Ravindrayep...@gmail.comwrote:
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[i];
}
}

}

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

May 24 '07 #2
On May 24, 9:25 pm, Darko <darko.maksimo...@gmail.comwrote:
On May 24, 3:16 pm, Ravi <Ravindrayep...@gmail.comwrote:
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[i];
}
}
}
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.

May 25 '07 #3
Ravi wrote:
On May 24, 9:25 pm, Darko <darko.maksimo...@gmail.comwrote:
>On May 24, 3:16 pm, Ravi <Ravindrayep...@gmail.comwrote:
<snip code>
>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.
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.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 25 '07 #4
On May 25, 8:13 am, -Lost <maventheextrawo...@techie.comwrote:
Ravi wrote:
On May 24, 9:25 pm, Darko <darko.maksimo...@gmail.comwrote:
On May 24, 3:16 pm, Ravi <Ravindrayep...@gmail.comwrote:

<snip code>
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.

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.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
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.

May 25 '07 #5

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.

May 26 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.