使用ajax将值输入类型文本发送到另一个php文件。

时间:2022-11-13 22:28:19

I'm trying to send the value of this

我想把它的值发送出去

<form class="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
      <input type="hidden" name="business" value="nineteenseventees@gmail.com">
      <input type="hidden" name="cmd" value="_xclick">
      <input type="hidden" name="upload" value="1">
      <input type="hidden" name="item_name" value="'.$fetch['ShirtType'].'-'.$fetch['ShirtSize'].'-'.$fetch['ShirtColor'].'">
      <input type="hidden" name="item_number" value="'.$fetch['itemnum'].'">
      <input type="hidden" name="quantity" value="'.$fetch['quantity'].'">
      <input type="hidden" name="amount" value="'.$fetch['ItemPrice'].'">
      <input type="hidden" name="currency_code" value="PHP">
      <input type="hidden" name="cancel_return" value="http://localhost/imageupload/index.php">
      <input type="hidden" name="return" value="http://localhost/imageupload/paysuccess.php">
      <input type="hidden" id="ordernumber" value="'.$fetch['OrderNum'].'">
      <button class="btn btn-primary pull-right" type="submit" id="paypalbutton" name="paypalbutton"><i class="fa fa-check"></i></button>

When I press the button, this go to paypal. But I want it to go to paypal via ajax and also save the OrderNum to session.

当我按下按钮时,它会转到贝宝。但是我想让它通过ajax传到paypal并保存OrderNum to会话。

I tried using AJAX but i can't seem to make it work. here it is

我尝试使用AJAX,但似乎无法实现。在这里

  $('#paypalbutton').on('click', function(e){
  var num = $("#ordernumber").val();
  $.ajax({
    type: 'POST',
    url: 'redirect.php',
    data: {
        onumber: num
    }
 }); 
});

I'm trying to send it here: redirect.php

我试着把它发送到这里:redirect.php

<?php
session_start();
require_once 'dbconnect.php';

$_SESSION['order'] = $_POST['onumber'];
echo $_SESSION['order'];

?>

2 个解决方案

#1


1  

$('.paypal').on('submit', function(e){
    e.preventDefault();
    var num = $("#ordernumber").val();
    $.ajax({
       type: 'POST',
       url: 'redirect.php',
       data: {
          onumber: num
       }
   }); 
});

#2


0  

First of All:

首先:

<button class="btn btn-primary pull-right" type="button" id="paypalbutton" name="paypalbutton"><i class="fa fa-check"></i></button>

Second:

第二:

      $('#paypalbutton').click(function(){
         var num = $("#ordernumber").val();
         $.post('redirect.php',{onumber:num},function(data){
           if(data){
              console.log(data);
              $(".paypal").submit();
           }

         }); 
      });

Replace this by your javascript code please and try once.

请用javascript代码替换它,并尝试一次。

#1


1  

$('.paypal').on('submit', function(e){
    e.preventDefault();
    var num = $("#ordernumber").val();
    $.ajax({
       type: 'POST',
       url: 'redirect.php',
       data: {
          onumber: num
       }
   }); 
});

#2


0  

First of All:

首先:

<button class="btn btn-primary pull-right" type="button" id="paypalbutton" name="paypalbutton"><i class="fa fa-check"></i></button>

Second:

第二:

      $('#paypalbutton').click(function(){
         var num = $("#ordernumber").val();
         $.post('redirect.php',{onumber:num},function(data){
           if(data){
              console.log(data);
              $(".paypal").submit();
           }

         }); 
      });

Replace this by your javascript code please and try once.

请用javascript代码替换它,并尝试一次。