简体   繁体   中英

Ajax Request Get Different Response Value From PHP

I have this ajax request code

$("#input_form").on("your change event",function(e){
        if(changeTimer !== false) clearTimeout(changeTimer);
        changeTimer = setTimeout(function(){
    $.ajax({
        type: 'POST',
        url: 'exchanger',
        data: $('#depo').serialize(), 
        beforeSend: function() {
            $("#result").addClass('deposit-input-loading');
        }
    }).done(function(t) {
        data = $.parseJSON(t);
        setTimeout(function() {
            $("#result").removeClass('deposit-input-loading');
            $("#ex_limit").html('min: '+data.value);
            $("#received_amount").val(data.receive_amount);
        }, 1000);
    })
            changeTimer = false;
        },50);
});

But error in after done function in ajax request. my PHP file code was like this

$rate = $API->getRate($send, $received, $amount);
$limits = $API->getLimits($send, $received);
echo json_encode($rate);
echo json_encode($limits);

the echo json_encode show different array How to get the response from different json_encode and show in ajax request?

Try this into your PHP File:

$rate = $API->getRate($send, $received, $amount);
$limits = $API->getLimits($send, $received);
$array = array('rate' => $rate, 'limits' => $limits); 
echo json_encode($array); exit; 

Then check your data variable in ajax done method.

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