post data to url/customer.php with javascript



  • 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");
    }



  • But what happened? You have any errors?



  • 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
    }
    
    ?>
    


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



  •   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()
           
                
            }
    


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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.