dora12345678 2014-10-22 15:17
浏览 79
已采纳

与Firefox的ajax兼容性问题

Hi I have created a website that has a form which actions directs to paypal payment. Before directing to paypal page, I created an ajax script that will read an external php file which will save my other data in the form to the database before directing to paypal. I got it work with IE and chrome, but for some reasons, which I don't know why it will not save the data using Firefox 20.0.1.

What I want is that I want to get it work in Firefox. Since this code runs in IE and Chrome.

Heres my internal ajax script:

<script>
    $(function () {
        $('#senrollnow').on('submit', function (e) {
          $.ajax({
            type: 'post',
            url: 'insert.php',
            data: $('#senrollnow').serialize(),
            success: function () {
              alert('form was submitted'+data);
            }
          });
        });
      });
</script>

My HTML Form (index.php):

<form action="https://www.paypal.com/cgi-bin/webscr" name="ligit" method="POST" id="senrollnow" target="_top" >
                            <div class="row">
                                <div class="large-12">
                                    <div class="row">
                                        <div class="large-6 columns">
                                            <input type="text" placeholder="First Name" name="first_name" required />
                                        </div>
                                        <div class="large-6 columns">
                                            <input type="text" placeholder="Last Name" name="last_name" required />
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="large-12 columns">
                                            <input type="email" placeholder="Email" name="email" required />
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="large-12 columns">          

                                            <input type="hidden" name="on0" value="Courses Options">Courses Options
                                            <select name="os0">
                                                <option value="Basic (30 mins)">Basic (30 mins) : $69.00 AUD - monthly</option>
                                                <option value="Basic (1 hour)">Basic (1 hour) : $129.00 AUD - monthly</option>
                                                <option value="Standard (30 mins)">Standard (30 mins) : $69.00 AUD - monthly</option>
                                                <option value="Standard (1 hour)">Standard (1 hour) : $129.00 AUD - monthly</option>
                                                <option value="International (30 mins)">International (30 mins) : $69.00 AUD - monthly</option>
                                                <option value="International (1 hour)">International (1 hour) : $129.00 AUD - monthly</option>
                                            </select> 
                                        </div>
                                    </div>
                                    <br/>
                                    <div class="row">
                                        <div class="large-12 large-centered columns text-center">
                                            <input type="hidden" name="currency_code" value="AUD">
                                            <input class="pulse-shrink" type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                                            <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
                                            <!--<input id="button_enroll" type="submit" name="ligit" placeholder="Email" class="button" value="Enrol Now!" /> -->
                                        </div>
                                    </div>
                                    <a class="close-reveal-modal">&#215;</a>
                                </div>
                            </div>
                        </form>

And my PHP: insert.php

require_once "dbconfig.php";

// escape variables for security
$firstname = mysqli_real_escape_string($con, $_POST['first_name']);
$lastname = mysqli_real_escape_string($con, $_POST['last_name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$type = mysqli_real_escape_string($con, $_POST['os0']);

$date = date_create();
$created = date_format($date, 'Y-m-d H:i:s');

$sql="INSERT INTO student (first_name, last_name, email, type, created)
VALUES ('$firstname', '$lastname', '$email', '$type', '$created')";

if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
}

header('Location: index.php');
  • 写回答

1条回答 默认 最新

  • duanre4421 2014-10-22 15:27
    关注

    as I understand you want to load some data to form before submitting it and after them sent form data by default way

    I thing you must to do actions send form to paypal and to your server separately. One way is to send ajax form and call event.preventDefault() to prevent default submitting form and on success callback you may do submitting.

    the simplest primitive way is to add a class to form e.g.

    $('#senrollnow').on('submit', function (e) {
          var form = $(this);
          if(!form.hasClass('pending')) {
              e.preventDefault();
              form.addClass('pending');
              $.ajax({
                  type: 'post',
                  url: 'insert.php',
                  data: $('#senrollnow').serialize(),
                  success: function () {
                    form.submit();
                    // alert('form was submitted'+data);
                  }
              });
          }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页