AJAX vs. Cookies - Am I just silly?

Discussion in 'Javascript' started by dougloj, Feb 17, 2007.

  1. dougloj

    dougloj Guest

    Hi.

    I have an ASP.NET application written in C#. In part of my
    application, I want to use JavaScript OnClick event function to
    update a textbox with a string generated asynchronously on the server.
    I have pretty much figured out two ways to this. One way involves
    AJAX. The other way involves using cookies.

    I think AJAX is awesome, but what if the user's browser blocks ActiveX
    controls? On the other hand what if the browser blocks cookies? Should
    I implement both ways of doing the task, and go the cookies route if
    ActiveX controls are blocked?

    Any thoughts are welcomed.

    Thanks for the bandwidth.

    -Doug
    dougloj, Feb 17, 2007
    #1
    1. Advertising

  2. On Feb 17, 12:38 pm, "dougloj" <> wrote:
    > Hi.
    >
    > I have an ASP.NET application written in C#. In part of my
    > application, I want to use JavaScript OnClick event function to
    > update a textbox with a string generated asynchronously on the server.
    > I have pretty much figured out two ways to this. One way involves
    > AJAX. The other way involves using cookies.
    >
    > I think AJAX is awesome, but what if the user's browser blocks ActiveX
    > controls? On the other hand what if the browser blocks cookies? Should
    > I implement both ways of doing the task, and go the cookies route if
    > ActiveX controls are blocked?
    >
    > Any thoughts are welcomed.



    I'm curious how cookies can replace an Ajax request. If you can send
    the string in a cookie then you know what should be in the textbox
    when you serve the page. In that case you don't need either Ajax or
    cookies. Just put the string in a JavaScript variable when you
    dynamically generate the page.

    So what exactly are you trying to do?

    Peter
    Peter Michaux, Feb 17, 2007
    #2
    1. Advertising

  3. dougloj

    dougloj Guest

    > I'm curious how cookies can replace an Ajax request. If you can send
    > the string in a cookie then you know what should be in the textbox
    > when you serve the page. In that case you don't need either Ajax or
    > cookies. Just put the string in a JavaScript variable when you
    > dynamically generate the page.
    >
    > So what exactly are you trying to do?
    >
    > Peter


    Peter,

    My ASP.NET application submits info to a database. Another application
    gets the info from the database and eventually replies by updating the
    database. The ASP.NET application the reply and shows the reply to the
    user. This all happens asynchronously.

    While the users is wainting, a small anamation is displayed. When the
    reply is ready, the animation is hidden and the reply is displayed.
    The animation and reply are each actually displayed on seperate .aspx
    pages that are viewed in the application by an iframe window.

    I want the user to be able to print the reply when it arrives.
    Unfortunately, my print process won't pick up the contents of the
    iframe which contains the reply.

    So, when the user clicks the Print button, I want to grab the reply
    text, assign it to a lable in an area on the page which will be picked
    up by the print process, and print it along with other info on the
    page.

    As I see it, I have 2 ways of "grabbing" the string. One way is to
    write the string to a cookie on the server when it's ready. My
    JavaScript code can check for the cookie when the Print button is
    clicked. The 2nd way is to write the string to a session variable on
    the server when the string is ready, and use AJAX to get the string
    when Print is clicked.

    Any ideas of a better way, or input on the AJAX vs. Cookie matter are
    welcomed.

    Thanks.

    Doug
    dougloj, Feb 18, 2007
    #3
  4. On Feb 17, 7:29 pm, "dougloj" <> wrote:
    > While the users is wainting, a small anamation is displayed. When the
    > reply is ready, the animation is hidden and the reply is displayed.
    > The animation and reply are each actually displayed on seperate .aspx
    > pages that are viewed in the application by an iframe window.
    >
    > I want the user to be able to print the reply when it arrives.
    > Unfortunately, my print process won't pick up the contents of the
    > iframe which contains the reply.


    Why not pick out the response from the iframe?

    Or set the focus to the iframe and then it'll print instead.

    Kev
    Kevin Darling, Feb 18, 2007
    #4
  5. dougloj

    dougloj Guest

    On Feb 17, 7:34 pm, "Kevin Darling" <> wrote:
    >
    > Why not pick out the response from the iframe?
    >
    > Or set the focus to the iframe and then it'll print instead.
    >
    > Kev


    Kev,

    I tried using the innerHTML and innerText of the iframe to get the
    response text, but they are empty. Do you know how to get the text
    content from an iframe in JavaScript?

    As far as the printing goes, I want to print the response text along
    with other info on the page. The other info is in a div. Right know, I
    write the response text to a cookie on the server when it's ready. My
    onClick function for the Print button checks the cookie. If the cookie
    exists, I grab the response text, put it in the innerText of a span
    within my div, and print the innerText of the whole div.

    The JavaScript code for the printing is as follows:

    // summaryDiv contains everything that is to be printed,
    // including the response span

    var summaryDiv = document.getElementById("summaryDiv");

    var WinPrint = window.open('','','letf=0,top=0,width=1,
    height=1,toolbar=0,scrollbars=0,status=0');

    WinPrint.document.write(summaryDiv.innerHTML);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();

    If you or anybody has any ideas about a better way to the print, how
    to get the text content of an iframe, or any thoughts on the AJAX vs.
    Cookies issue, I'd love to hear from you.

    Thanks.

    Doug
    dougloj, Feb 18, 2007
    #5
  6. dougloj

    The Magpie Guest

    dougloj wrote:
    >
    > I think AJAX is awesome, but what if the user's browser blocks ActiveX
    > controls? On the other hand what if the browser blocks cookies? Should
    > I implement both ways of doing the task, and go the cookies route if
    > ActiveX controls are blocked?
    >

    AJAX has nothing whatever to do with ActiveX. So - to answer your
    question about it - it is irrelevant if a user blocks ActiveX.
    Similarly, AJAX has nothing whatever to do with cookies and the answer
    to your second question is also that it is irrelevant.

    I have no idea what you mean by "both ways" since AJAX requires
    *neither* ActiveX *nor* cookies!
    The Magpie, Feb 19, 2007
    #6
  7. Hi,

    The Magpie wrote:
    > dougloj wrote:
    >> I think AJAX is awesome, but what if the user's browser blocks ActiveX
    >> controls? On the other hand what if the browser blocks cookies? Should
    >> I implement both ways of doing the task, and go the cookies route if
    >> ActiveX controls are blocked?
    >>

    > AJAX has nothing whatever to do with ActiveX. So - to answer your
    > question about it - it is irrelevant if a user blocks ActiveX.
    > Similarly, AJAX has nothing whatever to do with cookies and the answer
    > to your second question is also that it is irrelevant.
    >
    > I have no idea what you mean by "both ways" since AJAX requires
    > *neither* ActiveX *nor* cookies!


    To be fair, XmlHttpRequest in IE6 and older is created using an ActiveX
    component.

    However, I believe that even if the user blocks ActiveX, the blocking
    doesn't affect invisible ActiveX component. I might be wrong though.

    Greetings,
    Laurent
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering, Blog: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
    Laurent Bugnion [MVP], Feb 19, 2007
    #7
  8. dougloj

    Randy Webb Guest

    Laurent Bugnion [MVP] said the following on 2/19/2007 4:20 PM:
    > Hi,
    >
    > The Magpie wrote:
    >> dougloj wrote:
    >>> I think AJAX is awesome, but what if the user's browser blocks ActiveX
    >>> controls? On the other hand what if the browser blocks cookies? Should
    >>> I implement both ways of doing the task, and go the cookies route if
    >>> ActiveX controls are blocked?
    >>>

    >> AJAX has nothing whatever to do with ActiveX. So - to answer your
    >> question about it - it is irrelevant if a user blocks ActiveX.
    >> Similarly, AJAX has nothing whatever to do with cookies and the answer
    >> to your second question is also that it is irrelevant.
    >>
    >> I have no idea what you mean by "both ways" since AJAX requires
    >> *neither* ActiveX *nor* cookies!

    >
    > To be fair, XmlHttpRequest in IE6 and older is created using an ActiveX
    > component.
    >
    > However, I believe that even if the user blocks ActiveX, the blocking
    > doesn't affect invisible ActiveX component. I might be wrong though.


    If the user blocks ActiveX, then ActiveX is blocked. Meaning, if ActiveX
    is blocked then "AJAX" won't work in IE6 and prior IE browsers.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Feb 19, 2007
    #8
  9. Laurent Bugnion [MVP] wrote:
    > The Magpie wrote:

    <snip>
    >> AJAX has nothing whatever to do with ActiveX. ...

    <snip>
    > To be fair, XmlHttpRequest in IE6 and older is created
    > using an ActiveX component.
    >
    > However, I believe that even if the user blocks ActiveX,
    > the blocking doesn't affect invisible ActiveX component.
    > I might be wrong though.


    I don't know what you mean by "invisible ActiveX component". With the
    Internet security setting for "Script controls marked safe for scripting"
    set to disabled (and/or, I seem to recall, "Run ActiveX controls and
    plug-ins" disabled) the ActiveX XML HTTP request component cannot be
    instantiated in IE 6.

    Microsoft has suffered in the past from more controls being "marked safe
    for scripting" than actually were safe. The XML HTTP request object is
    not among that group, but the safe option (for the user) is still to
    disable that stetting for Internet use. And my money would be on a
    security update for IE 6 disabling it by default as soon as Microsoft
    think that the take-up of IE 7 is height enough for the loss of XML HTTP
    requests in IE 6 not to seem important to .NET customers.

    Richard.
    Richard Cornford, Feb 19, 2007
    #9
  10. Hi Randy,

    Randy Webb wrote:
    > Laurent Bugnion [MVP] said the following on 2/19/2007 4:20 PM:
    >>
    >> However, I believe that even if the user blocks ActiveX, the blocking
    >> doesn't affect invisible ActiveX component. I might be wrong though.

    >
    > If the user blocks ActiveX, then ActiveX is blocked. Meaning, if ActiveX
    > is blocked then "AJAX" won't work in IE6 and prior IE browsers.


    Thanks for the correction. I got to try that, I must have an old IE6
    running somewhere...

    Greetings,
    Laurent
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering, Blog: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
    Laurent Bugnion [MVP], Feb 19, 2007
    #10
    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. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,456
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,504
    Fredrik Lindner
    Nov 6, 2003
  3. minnie
    Replies:
    1
    Views:
    671
    Andrew Thompson
    Dec 13, 2006
  4. Rob Meade

    ASP.Net / AJAX - silly question perhaps

    Rob Meade, Jul 24, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    403
    Cowboy \(Gregory A. Beamer\)
    Jul 24, 2007
  5. _Who
    Replies:
    7
    Views:
    2,634
Loading...

Share This Page