douliaotong4944 2019-04-18 19:35
浏览 49

如何使用PHP修复“Ajax表单提交”

The code shown below employs the Ajax but there is an indefinite loading bar as if the function never gets called from the controller. How would I go about getting the HTML to successfully initiate this function?

//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();
       });

Below is the HTML with the wojo_form id as requested.

    <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>

If you need anything additional please let me know.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料