ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

AJAX asynchronous - html page doesn't receive the server answer from cgi program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX asynchronous - html page doesn't receive the server answer from cgi program

    My html page call a cgi program using XMLHttpRequest, if I define method synchronous, I receive the server answer (from iSeries v5r4) and the program works, if I define method asynchronous I don't receive the server answer (onreadychange never change)
    Someone can help me?

    This is the code:
    PHP Code:
    <script language=javascript>
    function 
    elabora() {
    pgmtocall '/cgigrp/vg24rh0a.cgi';
    stringpar 'cgcod=' document.getElementById("cgcod").value;

    if (
    window.XMLHttpRequest){
    var 
    client = new XMLHttpRequest();
    }
    else {
    var 
    client = new ActiveXObject("Microsoft.XMLHTTP");
    }
    client.open("POST",pgmtocall,true);
    client.onreadystatechange testfine(client);
    client.setRequestHeader("Content-Type""application/x-www-form-urlencoded");
    client.send(stringpar);
    }

    function 
    testfine(client) {
    if (
    client.readyState == 4) {
    if (
    client.status == 200) {
    document.getElementById("report").value codreport;
    }
    }
    }
    </
    script

  • #2
    Re: AJAX asynchronous - html page doesn't receive the server answer from cgi program

    Monica,

    I ain't no AJAX expert, but it might be worth just adding a unique field (eg
    timestamp) to your 'stringpar' when you do the call. I experienced problems
    with my AJAX request apparently not working and it was all down to the browser
    caching. Adding this unique field forced the request each time. Not connected
    at all to synchronous/asynchronous, but see if it makes any difference.

    If not there is always the yahoo group (Easy400) that are pretty experienced +
    helpful.

    Good luck!

    Comment


    • #3
      Re: AJAX asynchronous - html page doesn't receive the server answer from cgi program

      Thanks Andrew,
      just yesterday I found which was the problem.
      I changed the code like below
      client.onreadystatechange = function() { testfine(client); }

      and now the program works.

      Cheers, Monica

      Comment


      • #4
        Re: AJAX asynchronous - html page doesn't receive the server answer from cgi program

        You might like to take a look at prototype.js. It's a JavaScript library that contains numerous useful functions. Fed up of typing document.getElementByID('id');? With prototype you would just type $('ID')!

        It also cleans up a lot of the AJAX nasties for you. Here is an example of an AJAX request using prototype. I think this should work.
        PHP Code:
        var url '/cgigrp/vg24rh0a.cgi';
        var 
        pars 'cgcod=' + $("cgcod").value;
        var 
        target 'report';    
        var 
        myAjax = new Ajax.Updater(targeturl, {method'get'parameterspars}); 
        Also, there are some really good JavaScript libraries such as Scriptaculous and Rico built on top of prototype that contain all sorts of visual niceties.


        Ben

        Comment


        • #5
          Re: AJAX asynchronous - html page doesn't receive the server answer from cgi program

          I am with you on this one Bent.
          I Just wish I had more time or mandate to play with this stuff!


          Comment

          Working...
          X