必承其重 | 欲带皇冠 2015-09-08 18:30 采纳率: 0%
浏览 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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表