George_Fal 2017-03-16 17:52 采纳率: 0%
浏览 48

AJAX调用返回“未定义”

I'm trying to send value of Date to code behind while using an ajax call but it is returning. what am I doing wrong here

 function FetchTime() {
               debugger;
               var Pt_AppDate = document.getElementById("appdate").value;
               var reqs ='{AppointmentDate: "' + Pt_AppDate + '"}';
               $.ajax({
                    type: "POST",
                    url: "AppointmentForm.aspx/FetchATime",
                  data: reqs,
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    success: OnSuccessApptwo,
                    failure: function (response) { alert(response.d); },
                    error: function (response) { alert(response.d); }
               });

          }

Code Behind

public void FetchATime()
          {
               conn.ConnectionString = dbObj.connString;
               conn.Open();
               string query2 = "Select Appointment_time from Appointments where convert(date, Appointment_date) < '" + AppointmentDate + "'";
               SqlCommand cmd2 = new SqlCommand(query2, conn);
               AvailableTime.DataSource = cmd2.ExecuteReader();
               AvailableTime.DataTextField = "Appointment_time";
                DoctorName.DataValueField = "Symptom_id";
               AvailableTime.DataBind();
               AvailableTime.Items.Insert(0, new ListItem("--Select Available Time", "0"));
               conn.Close();
          }

</div>
  • 写回答

1条回答 默认 最新

  • 三生石@ 2017-03-16 17:59
    关注

    Your client-side code is trying to print a returned value:

    alert(response.d)
    

    but the server-side codes doesn't return a value:

    public void FetchATime()
    {
        //...
    }
    

    In order for something to be returned, you have to return something. (Something serializable of course.) For example:

    public SomeType FetchATime()
    {
        //...
        return someObject; // an instance of SomeType
    }
    

    Then in your client-side code you can access properties on that object:

    alert(response.someProperty)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据