2017-03-16 21 views
0

ajax呼び出しを使用している間にコードの背後にDateの値を送信しようとしていますが、戻ります。 は私がAJAX呼び出しが「未定義」を返します

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(); 
 
      }

答えて

0

あなたのクライアント側のコードが返された値を印刷しようとしている背景にはここで間違っ

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); } 
 
       }); 
 

 
      }

コードを何をやっている:

alert(response.d) 

が、値を返さないサーバー側のコード:

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

返されることを何かのためのためには、あなたが何かを返すことがあります。 (もちろん、シリアライズ何か。)例:

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

は、その後、あなたのクライアント側のコードで使用すると、そのオブジェクトのプロパティにアクセスすることができます。

alert(response.someProperty) 
関連する問題