AJAX Problem

Discussion in 'Javascript' started by Ravi, May 24, 2007.

  1. Ravi

    Ravi Guest

    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
    Ravi, May 24, 2007
    #1
    1. Advertising

  2. Ravi

    Darko Guest

    On May 24, 3:16 pm, Ravi <> 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;
    > }
    > }
    >
    > }
    >
    > 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).
    Darko, May 24, 2007
    #2
    1. Advertising

  3. Ravi

    Ravi Guest

    On May 24, 9:25 pm, Darko <> wrote:
    > On May 24, 3:16 pm, Ravi <> 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;
    > > }
    > > }

    >
    > > }

    >
    > > 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.
    Ravi, May 25, 2007
    #3
  4. Ravi

    -Lost Guest

    Ravi wrote:
    > On May 24, 9:25 pm, Darko <> wrote:
    >> On May 24, 3:16 pm, Ravi <> 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.
    -Lost, May 25, 2007
    #4
  5. Ravi

    Darko Guest

    On May 25, 8:13 am, -Lost <> wrote:
    > Ravi wrote:
    > > On May 24, 9:25 pm, Darko <> wrote:
    > >> On May 24, 3:16 pm, Ravi <> 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.
    Darko, May 25, 2007
    #5
  6. Ravi

    Ravi Guest

    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.
    Ravi, May 26, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    20
    Views:
    1,880
    d1srupt3r
    Mar 31, 2008
  2. darrel

    beginner AJAX questions (AJAX.net)

    darrel, Apr 27, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    2,423
    Flinky Wisty Pomm
    Apr 28, 2006
  3. jobs
    Replies:
    0
    Views:
    352
  4. =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?=

    Deploying ASP.NET AJAX-Enabled Web site to host without AJAX insta

    =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?=, Feb 20, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    582
    Patrick
    Feb 21, 2007
  5. minnie
    Replies:
    1
    Views:
    671
    Andrew Thompson
    Dec 13, 2006
Loading...

Share This Page