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

报告相同问题?