Passing AJAX GET results to location

0 votes

Here's my problem

<script type="text/javascript"><!--
$('#button-confirm').bind('click', function() {
    $.ajax({ 
        type: 'GET',
        url: 'index.php?route=payment/bitcoinpayflow/confirm',
        success: function(url) {
             location = '<?php echo $continue;?>';
        }       
    });
});
//--></script> 

The url returns this:

https://bitcoinpayflow.com/ordersArray // note the lack of space between orders and array. Is this a problem? If it is, I can get it to display in JSON notation with some fiddling.
(
    [order] => Array
        (
        [bitcoin_address] => 1DJ9qiga2fe94FZPQZja75ywkdgNbTvGsW
    )

)

Now, what I want to do is append the entry bitcoin_address to $continue '<?php echo $continue;?>'. which stands for: /index.php?route=checkout/success. so it would read /index.php?route=checkout/success&btc=1DJ9qiga2fe94FZPQZja75ywkdgNbTvGsW. it seems like it should be simple but I can't see how to do it.

The next page has a javascript function that parses the bitcoin address from the url and displays it on the page. This all works fine, I just can't get the bitcoin address to actually show!

Sep 4, 2018 in Blockchain by slayer
• 29,350 points
501 views

2 answers to this question.

0 votes

Make it return JSON. You will reduce the amount of pain a lot. Apparently it's PHP, so just use PHP's json_encode(), then just use the JSON response to concatenate stuff to url in your 'success' function.

location = "<?php echo $location; ?>&btc=" + data.bitcoin;

...or something like that. Try console.log(data) if you're not sure what you're getting.

answered Sep 4, 2018 by digger
• 26,740 points
0 votes

Set a variable in global scope and then access it within functions

<script type="text/javascript"><!--
var btcaddress = null;

$('#button-confirm').bind('click', function() {
    if( isValidBtcAddress( btcaddress ) ){
      Url = 'index.php?route=payment/bitcoinpayflow/confirm' + btcaddress;
    }else{
      Url = 'index.php?route=payment/bitcoinpayflow/confirm';
    }

    $.ajax({ 
        type: 'GET',
        'url': Url,
        success: function(url) {
             location = '<?php echo $continue;?>';
        }       
    });
});



function someotherFunction( response ){
    btcaddress = response['order']['bitcoin_address'];
}
answered Sep 4, 2018 by eddy

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

Is it possible to get wallet balance passing the wallet address on any cryptocurrency?

For Ethereum the API is called web3.eth.getBalance. There ...READ MORE

answered Apr 7, 2022 in Blockchain by Aditya
• 7,680 points
706 views
+1 vote
1 answer

How does a miner get to know that a transaction is verified by all the nodes?

Contrary to the popular belief, it is ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
2,510 views
0 votes
1 answer

How to get the already existing channels in Hyperledger v1.0?

You cannot see all available channels,  but you ...READ MORE

answered Jun 4, 2018 in Blockchain by Perry
• 17,100 points
2,293 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,142 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,690 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,231 views
0 votes
1 answer

How to get results by running the voting code on Ethereum?

In mist go to your contract and ...READ MORE

answered Sep 18, 2018 in Blockchain by digger
• 26,740 points
447 views
0 votes
1 answer

how to get modification history of asset?

You can use GetHistoryForKey() API as shown ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 26,740 points
1,292 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP