General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Asynchronous JavaScript?

  • jodekirk

    Asynchronous JavaScript?

    Participants 4
    Replies 5
    Last Activity 6 years, 6 months ago

    I have JavaScript code accessing a web service, but it locks up XMetaL until the request finishes. How do we use asynchronous JavaScript calls that do not lock up XMetaL?

    I have code similar to this:

    var entid = 40163132;
    var params = “[” + entid + “]”;
    var ASYNC = true;
    xmlhttp = new ActiveXObject(“MSXML2.XMLHTTP.6.0”);  // code for IE6, IE5 or XMetaL
    xmlhttp.open(“POST”, url, !ASYNC);
    xmlhttp.setRequestHeader(“content-type”, “application/json”);
    xmlhttp.send(params);
    var response = xmlhttp.responseText;
    var json = JSON.parse(response);

    Reply

    sajoss

    Reply to: Asynchronous JavaScript?

    xmlhttp = new ActiveXObject(“MSXML2.XMLHTTP.6.0”);  // code for IE6, IE5 or XMetaL
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    //async code in here
    var response = xmlhttp.responseText;
    var json = JSON.parse(response);
    }
    }
    xmlhttp.open(“POST”, url, true);
    xmlhttp.setRequestHeader(“content-type”, “application/json”);
    xmlhttp.send(params);

    this works for me but you may want to consider timeouts etc. if you cannot reach the server and also handling some other status although you will get no headers in Xmetal until you reach a readystate of 4 afaik. (I have been having a long painful journey with http requests in Xmetal)

    Reply

    jodekirk

    Reply to: Asynchronous JavaScript?

    I get an error on this line. How do you get past it?
    [code]if (xmlhttp.readyState == 4)[/code]
    0x800a138f – Microsoft JScript runtime error: 'xmlhttp.readyState' is null or not an object

    Any ideas?
    My code works fine if I change the async parameter to false. How do you do this in XMetaL with async set to true?

    Reply

    jodekirk

    Reply to: Asynchronous JavaScript?

    I figured it out. Thanks! I set the xmlhttp to null at the bottom of the function which broke the async code. It works now. Thanks!

    Reply

    Angelael

    Reply to: Asynchronous JavaScript?

    ADMIN –
    Any potential for integrating a chrome-like open source kit and updating this component to the modern web from within the application?

    Reply

    Derek Read

    Reply to: Asynchronous JavaScript?

    @Angelael: please contact XMetaL Support to make a feature request. Include as much information about your goals as possible so we can figure out why you think you need what you are requesting (there are often multiple ways to accomplish the same result). In other words, a request like: “our users need to be able to do X” is more useful than “please add support for Y”.

    Keep in mind that if what you ask for can already be accomplished it is unlikely a new feature would be implemented.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support