必承其重 | 欲带皇冠 2015-09-08 18:30 采纳率: 50%
浏览 14

$ .ajax POST问题

I am trying to use ajax POST method to validate course number on my page. The helper.html sends back correct value of i (true or false); that sets ValidCourse to true when it is a valid course. But when I check the value of ValidCourse after the ajax call; it always remains 'false'. Why?

if (EnrollmentsCount == 0) { // validate course 
    var crsNum = "'" + $j("#course_number").val() + "'";
    var ValidCourse = false;
    // Ajax call to determine if course is valid course 
    $.ajax({
        type: 'POST',
        url: 'helper.html?crsNum=' + crsNum,
        async: false,
        success: function(i) {
            if (i === 'true') {
                ValidCourse = true;
            }
        }
    });

    if (!ValidCourse) { //it is always false whether it is a valid or invalid course        
        var errorMsg = "Please enter valid course number";
        scroll('#course_number');
    }
}
  • 写回答

4条回答 默认 最新

  • weixin_33719619 2015-09-08 18:43
    关注

    can i see source code in helper.html ?

    maybe this problem you use

    var crsNum = "'" + $j("#course_number").val()  + "'";
    

    try to use

    var crsNum = $("#course_number").val();
    
    评论

报告相同问题?