我不是很擅長ajax,但我試圖在後面的代碼中調用一個方法來實現,如果存儲過程沒有返回數據或返回數據,並且if它正在返回數據,然後使該方法返回一個bool評估爲true。我正在傳遞一個id列表給該方法。 但是我的ajax調用可能是錯誤的。Ajax調用一直給我「內部服務器錯誤500」
這裏是我的ajax:
var hasExhibitLinked = false;
var selectedTasksList = getSelectedTaskIDs();
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/Tasks/ViewTasks.aspx/HasExhibitLinked")%>',
data: "{'taskID':['" + selectedTasksList.join(',') + "']}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
arr = data.d;
hasExhibitLinked = arr[0];
},
error: function (data) {
}
});
if (hasExhibitLinked) {
showMessage("There is an Exhibit linked.");
}
else {
showMessage("Not exhibits linked");
}
這裏是我的代碼背後,如果需要更多的信息: 編輯:
[WebMethod]
public static bool[] HasExhibitLinked(String[] taskID)
{
bool hasLink = false;
var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString());
var cmd = new SqlCommand("p_Link_List", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Taskid", SqlDbType.Int));
foreach (var id in taskID)
{
cmd.Parameters["@Taskid"].Value = taskID;
try
{
conn.Open();
String s = (String)cmd.ExecuteScalar();
if (s != null)
hasLink = true;
}
catch (SqlException sql)
{
ErrorLogger.Log(sql.Number, sql.Source, sql.Message);
}
catch (Exception ex)
{
ErrorLogger.Log(ex);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
}
return new bool[] { hasLink };
}
ASPX文件本身就是您的JavaScript嗎? –
yes .aspx – user1084319