0

I have a jquery code to retrieve data from shapeshift.io When I test using Postman, the data is ok. However, from the jQuery the data is undefined.

jQuery("#btnSubmit").click(function(){ 
    var param = {"withdrawal": "0x242AcBe58c4f3b514E72297EA0Ed0d847F1123BE" , "pair": "btc_eth"};

    jQuery.ajax({
        dataType    : 'json',
        type        : 'POST',
        contentType : 'application/json;charset=UTF-8',
        url         : 'https://shapeshift.io/shift',
        data        : JSON.stringify({data : param}),

        success: function(data,status) { 
            alert("Data: " + data.deposit + "\nStatus: " + status);
        },
        error: function(){
            alert("error");
        }


    });
 });

1 Answers1

0

is this the output you want? JSON.Stringify() takes one object and stringify's it.
check the snippet below:

jQuery("#btnSubmit").click(function(){
        var param = {"withdrawal": "0x242AcBe58c4f3b514E72297EA0Ed0d847F1123BE" , "pair": "btc_eth"};

        jQuery.ajax({
            dataType    : 'json',
            type        : 'POST',
            contentType : 'application/json;charset=UTF-8',
            url         : 'https://shapeshift.io/shift',
            data        : JSON.stringify(param),

            success: function(data,status) {
                alert("Data: " + data.deposit + "\nStatus: " + status);
            },
            error: function(){
                alert("error");
            }


        });
     });
<a href="#" id="btnSubmit">click</a>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>