XMLHttpRequest

Discussion in 'Javascript' started by William, Jan 23, 2006.

  1. William

    William Guest

    function saveText( scroll_list, t_area, listToBeUpdated ) {
    var updated = new Option();
    updated.value = t_area.value;
    updated.text = t_area.text;
    for(var i = 0; i < scroll_list.options.length; i++) {
    if( scroll_list.options.selected ) {
    scroll_list.options[scroll_list.selectedIndex].text = updated.value;
    scroll_list.options[scroll_list.selectedIndex].value= updated.value;
    break;
    }
    }
    var confirmReq;
    var url = "http://mkmxg00/cgi/confirmUpload.pl";
    confirmReq = new ActiveXObject( "Microsoft.XMLHTTP" );
    confirmReq.onreadystatechange = processReqChange;
    confirmReq.open( "POST", url, true );
    confirmReq.send( "" );

    alert( url );
    }
    function processReqChange() {
    alert( confirmReq.readyState );
    if ( confirmReq.readyState == 4 ) {
    if ( confirmReq.status == 200 ) {
    // process the response if successful
    alert( "passed!" );
    }
    }
    else {
    alert( confirmReq.readyState + ", " + confirmReq.status );
    }
    }

    my question:
    how do I check what content is being sent over to
    http://mkmxg00/cgi/confirmUpload.pl

    in the XMLHttpRequest?
     
    William, Jan 23, 2006
    #1
    1. Advertisements

  2. This is nonsense because you do not really use `updated' later.


    Assigning t_area.value is equivalent, however you probably wanted
    to assign t_area.text. And are you really sure you want to make all
    selected items the same?
    Assigning t_area.value is equivalent.
    ^^
    Ask in a Perl or CGI-related newsgroup about how to process a (POST)
    request.
    What you pass as the argument of confirmReq.send() becomes the body of the
    request which is evaluated _server-side_. The IXMLHTTPRequest interface
    which provides _client-side_ access to the _response_ of the request does
    not provide a property to access the request body later.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 23, 2006
    #2
    1. Advertisements

  3. William

    William Guest



    To make a long story short, I was asked by [another person, whose's
    instructions I have to follow] to scrap my code with XMLHttpRequest and
    possibly update the server text file with server side javascript.

    The current process:
    1) web browser displays values of server side text file thru the GUI
    2) the user modifies the values in this text file thru the GUI
    3) such modifications needs to be reflected on the server side text file.

    Assuming I successfully embedded the server side javascript code which
    updates the server side text file; how do I send an HTTP request for a 2nd
    time (i.e. after the user has made the changes), so that my server side
    javascript code actually updates the server side text file?

    This is my first time writing server side javascript, any
    suggestions/references is appreciated.

    (I am currently reading up on:
    http://docs.sun.com/source/816-6411-10/jsserv.htm#1024580)
     
    William, Feb 6, 2006
    #3
  4. In case you misunderstood me saying that (client-side) XMLHTTP requests are
    a Bad Thing, that was not the case.

    Are you saying that you now must implement a JS solution also server-side,
    instead of a Perl solution?
    I am not sure that you understood the difference between client-side and
    server-side code, and I am not sure if I understood you correctly. For
    one, HTTP requests AIUI you need them to transmit user modifications from
    the client to the server have to be initiated from the client, not from the
    server. And since client-side script code does not change, no matter the
    server-side code (unless the server-side code generates the sending
    client-side one), you just send the same request with different data again.
    The server always sends a response, not a request, to the client; this
    response can of course include any data you want, including the changed
    text file content. So you do not need another request just to show the
    updated data, not matter the programming language used to create the
    response.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 6, 2006
    #4
  5. William

    Randy Webb Guest

    William said the following on 2/6/2006 11:27 AM:
    Place the contents of the text file in a textarea with a submit button.
    Submit the form, let the server update as appropriate.
     
    Randy Webb, Feb 6, 2006
    #5
  6. William

    William Guest

    I was taking over somebody else's Perl script, and within the Perl script
    also contains javascript code.
    The 1st request was sent by the user typing the URL in the location bar of
    his brower.
    How do I send the 2nd HTTP request with the user's click of a button?
    But the user modifications are made after the server send the response
    (i.e. the HTML page that the user uses to update the server side text
    file). So I still need to send a 2nd HTTP request.
     
    William, Feb 6, 2006
    #6
  7. William

    William Guest

    I was taking over somebody else's Perl script, and within the Perl script
    also contains javascript code.
    The 1st request was sent by the user typing the URL in the location bar of
    his brower.
    How do I send the 2nd HTTP request with the user's click of a button?
    But the user modifications are made after the server send the response
    (i.e. the HTML page that the user uses to update the server side text
    file). So I still need to send a 2nd HTTP request.
     
    William, Feb 6, 2006
    #7
  8. AFAIK a Perl script cannot contain "javascript code". It can generate
    JavaScript code.
    I see.
    I do not understand this question, considering the code you posted before.
    And what is the problem, exactly?


    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 6, 2006
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.