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

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错