【问题标题】:Passing AJAX GET results to location将 AJAX GET 结果传递到位置
【发布时间】:2012-04-25 19:03:05
【问题描述】:

这是我的问题

<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> 

网址返回:

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
    )

)

现在,我要做的是将条目 bitcoin_address 附加到 $continue '&lt;?php echo $continue;?&gt;'。代表:/index.php?route=checkout/success。所以它会写成/index.php?route=checkout/success&amp;btc=1DJ9qiga2fe94FZPQZja75ywkdgNbTvGsW。看起来应该很简单,但我不知道该怎么做。

下一页有一个javascript函数,它从url解析比特币地址并显示在页面上。这一切都很好,我只是无法让比特币地址实际显示!

【问题讨论】:

  • 如果您对如何更好地格式化此问题有任何提示,请告诉我。我不习惯 stackoverflow 的礼仪。

标签: php ajax get opencart bitcoin


【解决方案1】:

让它返回 JSON。你会减少很多痛苦。显然它是 PHP,所以只需使用 PHP 的 json_encode(),然后只需使用 JSON 响应将内容连接到“成功”函数中的 url。

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

...或类似的东西。如果你不确定你得到了什么,试试 console.log(data)。

【讨论】:

  • 好的,它现在返回 json。特别是 { "order" : { "bitcoin_address" : "1F2vgWSRcfRzZz1LetFxrk6qfWhpTeW32s"} } + data.bitcoin。这是否是说“在数组中附加以 order 开头的条目,然后转到比特币”所以对我来说它将是 order.bitcoin_address ?感谢您的帮助,欢迎来到 stackoverflow(充满绝望的人文学科毕业生:))
【解决方案2】:

在全局范围内设置一个变量,然后在函数中访问它

<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'];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多