Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling php script from ajax in qt
Forum Updated to NodeBB v4.3 + New Features

Calling php script from ajax in qt

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venkatesh.rajavetrivel
    wrote on 28 Sept 2012, 06:44 last edited by
    #1

    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") {
    
            req.overrideMimeType("text/xml");
    
        }
    
    } 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
    
    req.open("GET", "info.php", true);
    
    // Transmit the request
    
    req.send(null);
    

    }
    @
    ////////////////////////////////////////////////
    The info.php page contains,

    <?php
    echo "HEloo";
    ?>

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    I am getting output in Qt console as,

    <?php
    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]

    1 Reply Last reply
    0
    • 0 Offline
      0 Offline
      02JanDal
      wrote on 28 Sept 2012, 08:31 last edited by
      #2

      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)

      Jan

      1 Reply Last reply
      0
      • V Offline
        V Offline
        venkatesh.rajavetrivel
        wrote on 28 Sept 2012, 10:42 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        28 Sept 2012, 06:44

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved