从即时发布

时间:2012-07-07 07:53:12

标签: php javascript jquery html

我有Paypal课程,我想回复表格,然后在用户点击付费后提交。我已经尝试过javascript,但它不适用于我。

if(isset($_SESSION['user_id']))
{

include('includes/class_paypal.php');
include 'includes/class_order.php';
include 'includes/class_user.php';
include 'includes/class_permission.php';
include('includes/adminfunctions_status.php');

$invoice = new paypal();
$order = new order($_GET['pay']);


$invoice->custom = $_GET['pay'];
$invoice->amount = $order->price;
$invoice->item_name = 'Order #'.$order->id.'';
$invoice->item_number = $order->id;
$invoice->init();
}

?>

<script type="text/javascript">

$(document).ready(myfunc () {
        var frm = document.getElementById("order");
        frm.submit();
    }

</script>

PayPal Class

    var $cmd = "_xclick";
    var $business = "**";
    var $item_name;
    var $item_number;
    var $amount;
    var $no_shipping = 1;
    var $no_note = 1;
    var $currency_code = "USD";
    var $lc = 'US';
    var $bn = "PP-BuyNowBF";
    var $return;
    var $cancel_return;
    var $rm = 2;
    var $notify_url;
    var $custom;

    function init()
    {
        echo '

        <form id="order" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
        <input type="hidden" name="cmd" value="_cart"> 
        <input type="hidden" name="business" value="'.$this->business.'"> 
        <input type="hidden" name="item_name" value="'.$this->item_name.'"> 
        <input type="hidden" name="item_number" value="'.$this->item_number.'">
        <input type="hidden" name="amount" value="'.$this->amount.'">  
        </form>



        ';
    }

正如您所见,我想在初始化订单信息后发布表单。因此,当用户转到index.php?pay = 45(45是订单号)时,我希望文件显示表单和所有内容,然后将表单发布到Paypal。

2 个答案:

答案 0 :(得分:0)

尝试:

$(document).ready(function() {
  var frm = document.getElementById("order");
  frm.submit();
});

或者

$(document).ready(function() {
   $('#order')[0].submit();
});

答案 1 :(得分:0)

试试这个:

 jQuery(document).ready(function(){
          setTimeout(function(){
             var frm = document.getElementById("order");
             frm.submit();              

          },10000);
    });

这会将提交延迟10秒,以便用户可以查看表单。