dp5657087 2015-10-26 05:14
浏览 11
已采纳

无法在modal -closed-中调用函数

I'm quite new with web development. I have a register modal in register.php that is able to return a check function from the submit button, to submit an API call.

enter image description here

But when I run this it from my index page, the function does not seem to be called.

enter image description here

header.php

<?php 
   include ('includes/login.php');
   include ('includes/register.php');
?>

register.php

<button class="regsubmit" type="submit" style="float:left;" id="submitButton" onclick="return chk()">Submit</button>
            <button class="regcancel" type="button" id="cancelButton"
                onclick="window.location='#';return false;">Cancel</button>
    </form>
    </div>
  </div>
</div>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
function chk() {
    var fname=document.getElementById('fname').value;
    var lname=document.getElementById('lname').value;
    var emailAddress =  document.getElementById('emailAddress').value;
    var bdayMonth = document.getElementById('bdayMonth').value;
    var bdayDay = document.getElementById('bdayDay').value;
    var bdayYear = document.getElementById('bdayYear').value;
    var regPassword = document.getElementById('regPassword').value;
    var confirmPassword = document.getElementById('confirmPassword').value;
    var gender = document.getElementById('gender').value;
    var dataString='fname='+ fname+'&lname='+lname+'&emailAddress='+emailAddress+'&bdayMonth='+bdayMonth+'&bdayDay='+bdayDay+'&bdayYear='+bdayYear+'&confirmPassword='+confirmPassword+'&regPassword='+regPassword+'&gender='+gender;

    $.ajax({
        type:"post",
        url: "processRegister.php",
        data:dataString,
        cache:false,
        success: function(data){
        if (/^\s*SUCCESS\s*$/.test(data)) {
        window.location = '<?php echo $base_url; ?>index.php?success=true';
           }
        else{
             alert(data);
          }
        }
    });
        return false;
}
</script>

edit: i ran an alert() at the start of the function and tried to run in on my index again, the alert was able to show but not the function.

  • 写回答

2条回答 默认 最新

  • douxuexiao1748 2015-10-26 05:53
    关注

    Thanks for the answers but was finally able to solve it after ensuring everything was loaded as mentioned above. After checking with alert that the function was running, i concluded that it was my ajax error. Seems like it couldn't access my processRegister.php which was located inside my includes folder, had to link it properly and it's all good. Another way was to move my processRegister.php outside of the folder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容