2013-10-27 32 views
0

我有兩個在同一頁面上提交的獨立函數(listing_details.tpl.php)。一個不會工作,我想也許是因爲其中一個提交使用了AJAX。任何可能的解決方案都是我的耳朵。在同一頁上提交多個'Submit'按鈕

在控制檯中的錯誤對於book_it_button讀取

POST http://staynsurf.biz/modules/listing/post.php 404 (Not Found) 

的Javascript

function subTotal() { 
    var check_in = $('#checkin').val(); 
    var check_out = $('#checkout').val(); 
    var guest = $('#number_of_guests').val(); 

if(check_in!='' && check_out!='' && guest!='') { 
    $('.spinner').show(); 
    $.ajax({ 
     type: "POST", 
     url: '<?php print SITE_MOD; ?>listing/ajax_subtotal.php', 
     data: $('#book_it_form').serialize(), 
     dataType:'json', 
     success: function(data) { 
      $('.spinner').hide(); 
      if(data['result'] == 'success'){ 
       $('#subtotal').html('<?php echo $_SESSION["ses_currency_symbol"]; ?>'+data['pricing']); 
       $('#book_it_button').removeAttr('disabled'); 
       $('#show_more_subtotal_info').css({'display':'block'}); 
       $('#service_fee').html('<?php echo $_SESSION["ses_currency_symbol"]; ?>'+data['service_fee']); 
       $('#sub_total').val(data['pricing']); 
       $('#serviceFee').val(data['service_fee']); 
      } else { 
       $('#book_it_enabled').css({'display':'none'}); 
       $('#show_more_subtotal_info').css({'display':'none'}); 
       $('#book_it_disabled').css({'display':'block'}); 
       $('#book_it_disabled_message').html(data['error']); 
       return false; 
      } 
     } 
    }); 
    return false; 
} 
} 

$("#checkin, #checkout").attr('readOnly' , 'true'); 
$("#checkin, #checkout").keypress(function(event) {event.preventDefault();}); 
$(function() { 
var dates = $("#checkin, #checkout").datepicker({ 
    minDate:0, 
    maxDate:"+3Y", 
    nextText:"", 
    prevText:"", 
    numberOfMonths:1, 

    changeMonth: false, 
    onSelect: function(selectedDate) { 
     var option = this.id == "checkin" ? "minDate" : "maxDate", 
     instance = $(this).data("datepicker"), 
     date = $.datepicker.parseDate(
     instance.settings.dateFormat || 
     $.datepicker._defaults.dateFormat, 
     selectedDate, instance.settings); 

     dates.not(this).datepicker("option", option, date); 
     var i=$.datepicker._defaults.dateFormat; 
     j=$.datepicker.parseDate(i,$("#checkin").val()); 
     l=$.datepicker.parseDate(i,$("#checkout").val()); 
    }, 
    onClose: function(){ 
     $('#book_it_button').attr({'disabled':'disabled'}); 
     $('#subtotal').html(''); 
     $('#show_more_subtotal_info').css({'display':'none'}); 
     $('#book_it_disabled').css({'display':'none'}); 
     $('#book_it_enabled').css({'display':'block'}); 
     if(this.id== "checkin") { 
      var theDate = new Date($(this).datepicker('getDate')); 
      // this sets "theDate" 1 day forward of start date 
      theDate.setDate(theDate.getDate() + 1); 
      // set min date for the end date as one day after start date 
      $('#checkout').datepicker('option','minDate',theDate); 
     } 
     subTotal(); 
    } 
}); 
}); 

輸入相關的book_it_button

<button type="submit" class="button-glossy green" id="book_it_button" disabled="disabled"> 

的JavaScript等提交

 <script type="text/javascript"> 
    $(function() { 
    $('form').on('submit', function (e) { 
     $.ajax({ 
     type: 'post', 
     url: 'post.php', 
     data: $('form').serialize(), 
     success: function() { 
      alert('form was submitted'); 
     } 
     }); 
     e.preventDefault(); 
    }); 
    }); 
</script> 
+5

404這個PHP文件不存在 – Lachezar

+0

問題可以在此頁面... HTTP上找到。 「預訂」按鈕會進入一個頁面confirm_booking.php,但在爲衝浪預測安裝JavaScript後,它只會看到當我點擊「預訂」功能 – pmanning

回答

0

將每個提交按鈕和相關字段放在它自己的部分中。 ?//staynsurf.biz/modules/listing/listing_details.php 1169 -