下面显示的代码使用了Ajax,但是有一个不确定的加载条,就好像从未从控制器调用该函数一样。我将如何使HTML成功启动此功能?
//HTML
<button type="button" data-url="/ajax/controller.php" name="dosubmit" class="wojo button positive">Approve</button>
<input name="ProcessApproval" type="hidden" value="1">
//Function
public function ProcessPOApproval()
{
$PID = $_GET['pid'];
$ApprovalTransactionalData = array(
'PONum' => "$PID",
'Step' => "4"
);
self::$db->insert("accounting_transact", $ApprovalTransactionalData);
}
//Controller
<?php
/* == Proccess Project File == */
if (isset($_POST['ProcessApproval'])):
if (intval($_POST['ProcessApproval']) == 0 || empty($_POST['ProcessApproval'])):
die();
endif;
ProcessPOApproval();
endif;
?>
//Ajax
/* == Master Form == */
$('body').on('click', 'button[name=dosubmit]', function() {
posturl = $(this).data('url')
function showResponse(json) {
if (json.status == "success") {
$(".wojo.form").removeClass("loading").slideUp();
$("#msgholder").html(json.message);
} else {
$(".wojo.form").removeClass("loading");
$("#msgholder").html(json.message);
}
}
function showLoader() {
$(".wojo.form").addClass("loading");
}
var options = {
target: "#msgholder",
beforeSubmit: showLoader,
success: showResponse,
type: "post",
url: SITEURL + posturl,
dataType: 'json'
};
$('#wojo_form').ajaxForm(options).submit();
});
下面是具有wojo_form id的HTML。
<form id="wojo_form" name="wojo_form" method="post">
<div class="three fields">
<div class="field">
<label>Submitting Accountant</label>
<label class="input"><i class="icon-prepend icon calendar"></i>
<input type="text" value="" disabled="disabled" name="created">
</label>
</div>
<div class="field">
<label>Next Approval</label>
<label class="input"><i class="icon-append icon calendar"></i>
<input type="text" value="<?php echo $row->lastlogin;?>" disabled="disabled" name="lastlogin">
</label>
</div>
<div class="field">
<label>Approval Group</label>
<label class="input"><i class="icon-prepend icon laptop"></i>
<input type="text" value="<?php echo $row->lastip;?>" disabled="disabled" name="lastip">
</label>
</div>
</div>
<div class="wojo double fitted divider"></div>
<button type="button" data-url="/ajax/controller.php" action="" name="dosubmit" class="wojo button">Decline Approval</button>
<input name="ProcessDecline" type="hidden" value="1">
<button type="button" data-url="ajax/controller.php" name="dosubmit" class="wojo button positive">Approve</button>
<input name="ProcessApproval" type="hidden" value="1">
<button type="button" data-url="/ajax/controller.php" name="dosubmit" class="wojo button info">Add Notes</button>
<input name="ProcessNotes" type="hidden" value="1">
</form>
如果您需要其他任何东西,请告诉我。