Je ne suis pas très bon avec ajax mais j'essaie d'appeler une méthode dans le code derrière cehck si une procédure stockée ne renvoie aucune donnée ou retourne des données, et si il renvoie des données, puis rend la méthode retourne un bool évaluant à vrai. Je passe une liste d'identifiants à la méthode. Cependant, mon appel ajax est probablement faux.Ajax appel continue de me donner "erreur serveur interne 500"
Voici mon 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");
}
ici est mon code derrière si plus d'informations sont nécessaires: EDIT:
[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 };
}
Est-ce que votre JavaScript est dans le fichier ASPX lui-même? –
oui dans le .aspx – user1084319