2013-10-27 26 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 -