Important: Please read the Qt Code of Conduct -

Calling php script from ajax in qt

  • I know that we can use ajax in qt qml. but I am getting all data including <?php ?> from info.php as result, when I use info.php as requesting URL in ajax.
    For example,
    function createXMLHttpRequest() {

    var req = null;
    try {
        req = new XMLHttpRequest();
        // Make sure that the browser supports overrideMimeType
        if (typeof req.overrideMimeType != "undefined") {
    } catch (ex) {
        req = null;
    return req;


    // Loads target XML document into XMLHttpRequest

    function loadXMLDoc(req) {

    // Register a callback function which gets called when the request state
    // changes
    req.onreadystatechange = function() {
        // Request states are 0 through 4, where 4 equals complete
        if (req.readyState == 4) {
            // Server returns numeric code 200 for "OK".
            if (req.status == 200) {
                test.text = req.responseText;
            } else {
                test.text = req.responseText;
    // Open an asynchronous (asyncFlag = true) request to the specified URL"GET", "info.php", true);
    // Transmit the request

    The info.php page contains,

    echo "HEloo";

    I am getting output in Qt console as,

    echo "HEloo";


    but, I need the the response text to be "HEloo" as we always get it in general ajax process.

    [Edit: Added @ tags to code -- mlong]

  • Is your .php page on a web page?

    If you only request the file from the local filesystem you will of course get the file as is.

    You would have to setup a server (take a look at apache, but there are many others), including PHP, and then request the file via an URL like http://localhost/info.php. The info.php file has of course to be in the server root (htdocs if apache)


  • Wow........ Great....... It is working....... Thanks a lot JanDal :)

Log in to reply