Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > AJAX Problem

Reply
Thread Tools

AJAX Problem

 
 
Ravi
Guest
Posts: n/a
 
      05-24-2007
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

 
Reply With Quote
 
 
 
 
Darko
Guest
Posts: n/a
 
      05-24-2007
On May 24, 3:16 pm, Ravi <(E-Mail Removed)> wrote:
> 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).

 
Reply With Quote
 
 
 
 
Ravi
Guest
Posts: n/a
 
      05-25-2007
On May 24, 9:25 pm, Darko <(E-Mail Removed)> wrote:
> On May 24, 3:16 pm, Ravi <(E-Mail Removed)> wrote:
>
>
>
> > 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.

 
Reply With Quote
 
-Lost
Guest
Posts: n/a
 
      05-25-2007
Ravi wrote:
> On May 24, 9:25 pm, Darko <(E-Mail Removed)> wrote:
>> On May 24, 3:16 pm, Ravi <(E-Mail Removed)> wrote:


<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.
 
Reply With Quote
 
Darko
Guest
Posts: n/a
 
      05-25-2007
On May 25, 8:13 am, -Lost <(E-Mail Removed)> wrote:
> Ravi wrote:
> > On May 24, 9:25 pm, Darko <(E-Mail Removed)> wrote:
> >> On May 24, 3:16 pm, Ravi <(E-Mail Removed)> wrote:

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

 
Reply With Quote
 
Ravi
Guest
Posts: n/a
 
      05-26-2007

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An Ajax Dictionary... My first AJAX project... GreatDomainz@gmail.com HTML 20 03-31-2008 01:24 PM
Deploying ASP.NET AJAX-Enabled Web site to host without AJAX insta =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?= ASP .Net 2 02-21-2007 10:22 PM
AJAX IDE and AJAX TOOL--The Release of JoyiStar AJAX WebShop 3 Beta minnie Java 1 12-13-2006 06:29 AM
Ajax installed.. where are Ajax controls like popup in my VS toolbox ?? jobs ASP .Net 0 11-06-2006 01:23 AM
beginner AJAX questions (AJAX.net) darrel ASP .Net 5 04-28-2006 06:42 PM



Advertisments