简体   繁体   中英

Data is not received on PHP page using $.POST() method of jquery

My POST variable at PHP page is always empty still after clicking on submit button. I send data from a javascript page to php page.

Javascript code:

$('#btnSubmit').click(function(){
    if(quantityArray[j] == undefined){
        alert("Empty Form can not be submitted!");
    }
    else {
        $.post('insert_man_order.php',{ total_price: quantityArray[j] }, function(data){
            alert(data);
        });
    }
});

The PHP code where i should receive the value of variable total_price is:

if(isset($_POST['total_price'])){
        $price = $_POST['total_price'];
    }
    else{
        echo "No data recieved";
    }

One more thing here.. I have written alert by passing data into it in $.post function and it works perfect. So if data is received perfectly after passing it to another page than whats the problem in receiving it at another page?

Instead of

if (isset($_POST['total_price'])) {
        $price = $_POST['total_price'];
}
else {
        echo "No data recieved";
}

do this

if (isset($_POST['total_price'])) {
        echo $_POST['total_price'];
}
else {
        echo "No data received";
}

you must print the data to make an ajax response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM