要拍摄,这是我的问题。我有一个脚本通过ajax发送Form POST请求,但我的问题是我想在A Href标签中执行。下面是我的FORM POST请求代码:
<script type="text/javascript">
$(document).ready(function(){
$( ".searchForm" ).submit(function( event ) {
event.preventDefault();
var invoiceNo=$(".invoiceNo").val();
var dataString = 'invoiceNo='+invoiceNo;
$.ajax ({
type: "POST",
url: "<?php echo base_url(); ?>/billing/test",
data: dataString,
cache: false,
success: function(html) {
$(".particularList_output").html(html);
}
});
});
});
</script>
<form action="/" class="searchForm">
<input type="hidden" class="invoiceNo" value="thisIsMyValue">
<button id="xSmall" type="submit" class="btn btn-primary">Add Invoice</button>
</form>
答案 0 :(得分:1)
做这样的事情:
<a href="<?php echo base_url();?>/billing/test" data-invoice="<?php echo $yourInvoiceNumber?>"> Add Invoice </a>
$('a').on('click', function(e){
e.preventDefault();
var $this = $(this);
$.ajax({
url: $this.data('href'),
type: 'POST',
data: 'invoiceNo='+$this.data('invoice'),
cache: false,
success: function(html) {
$(".particularList_output").html(html);
}
});
});