~Onlooker 2013-08-16 10:07 采纳率: 0%
浏览 35

Ajax请求不起作用

I am trying to get data from db using ajax. When a date is selected from inline calender then that date will be captured and query will be done and ive to show the holiday status of the selected date. but the ajax request is not working, how to know whether it is working or not.

my code is

$(function () {
    $("#divCalendar").datepicker({
        dateFormat: "mm-dd-yy",
        onSelect: function (selectedDate) {
            //alert("You clicked on " + selectedDate.toString());
            var dataString = 'sdt='+ selectedDate.toString();
            //alert("You clicked on " + dataString);
            $.ajax({
                type: "POST",
                url:"demotest.php",
                data: dataString,
                dataType : "json",
                success:function(data){
                    if(data != "ERROR")  
                    {
                        $("#div1").html(data);
                    }
                    else
                    {
                        $("#div1").html("nothing found");    
                    }
                }
            });
        }
    });
});    
  • 写回答

2条回答 默认 最新

  • weixin_33720186 2013-08-16 10:16
    关注

    in $.ajax, dataType parameter refers to the type of data that you're expecting back from the server as ajax response. You are setting that in your call to json.

    But the line

    $("#div1").html(data);
    

    seems like you are expecting a normal text or html response. If the response is not valid json the ajax call will not work. Else you remove the dataType : "json", line and let the ajax utility look for a default text response.

    You can get hints regarding the error encountered in your ajax call by checking the browser console (chrome inspector/firebug).

    评论

报告相同问题?

悬赏问题

  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现