Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. post data to url/customer.php with javascript
QtWS25 Last Chance

post data to url/customer.php with javascript

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 1.6k Views
  • 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.
  • mehmetakM Offline
    mehmetakM Offline
    mehmetak
    wrote on last edited by
    #1

    hi guys . i can send data with get method but i cant send data with post method
    i need help ... i ve stacked ... thx
    qt quick code javascript
    function getData() {
    var xmlhttp = new XMLHttpRequest();
    var url = "http://localhost/works/customers.php";
    //time.text = "yükle"
    var params = "lorem=ipsum&name=binny";
    xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState == XMLHttpRequest.DONE && xmlhttp.status == 200) {
    myFunction(xmlhttp.responseText);
    //siparisList.model.append(xmlhttp.responseText);
    }
    }
    xmlhttp.open("POST", url, true);
    xmlhttp.send("lorem=ipsum");
    }

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pyroxar
      wrote on last edited by
      #2

      But what happened? You have any errors?

      1 Reply Last reply
      0
      • mehmetakM Offline
        mehmetakM Offline
        mehmetak
        wrote on last edited by
        #3

        there is no error .
        server side simple test php code here .

        <?php
        if (isset($_POST['lorem'])) {
        ?>
        
        [ {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"}, {"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"}, {"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"}, {"Name":"Around the Horn","City":"London","Country":"UK"}, {"Name":"B's Beverages","City":"London","Country":"UK"}, {"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"}, {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"}, {"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"}, {"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"}, {"Name":"Bon app'","City":"Marseille","Country":"France"}, {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"}, {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"}, {"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"}, {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"}, {"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"} ]
        
        <?php
        
        } else {
        	?>
        		[ {"Name":"Mehmet AK","City":"Antalya","Country":"Türkiye"} ]
        
        	<?php
        }
        
        ?>
        
        1 Reply Last reply
        0
        • LunoL Offline
          LunoL Offline
          Luno
          wrote on last edited by
          #4

          How are you calling the function? and what is it myFunction?

          1 Reply Last reply
          0
          • mehmetakM Offline
            mehmetakM Offline
            mehmetak
            wrote on last edited by
            #5
              function myFunction(response) {
                        var arr = JSON.parse(response);
                        console.log(arr.length);
            
                        for(var i = 0; i < arr.length; i++) {
                            siparisList.model.append( {listdata: arr[i].Name +" "+ arr[i].City +" "+ arr[i].Country });
                            time.text =arr[i].Name;
                        }
                    }
            
             MouseArea {
                    anchors.fill: parent
                    onClicked: {
                      
                         console.log(factorial(10))
                        getData()
                   
                        
                    }
            
            1 Reply Last reply
            0
            • mehmetakM Offline
              mehmetakM Offline
              mehmetak
              wrote on last edited by
              #6

              this code solve my problem . ```
              xmlhttp.open("POST", url, true);
              xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

              1 Reply Last reply
              0

              • Login

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