我的DELETE请求有问题。当方法存在时,它会保持返回404找不到。我尝试过POST方法,但它确实有用,所以我不知道发生了什么。下面是我的请求方法的jQuery。
$(document).ready(function () {
var table = $('#example').DataTable();
$('#example tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
} else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
$('#button').click(function () {
var person = new Object();
var dbname = document.getElementById('Label2');
//alert(dbname.innerHTML);//db table name
var data = table.cell('.selected', 0).data()
//alert(String(data));//ID
person.name = dbname.innerHTML;
person.surname = String(data);
$.ajax({
url: "http://172.20.129.139/fa/summary.aspx/relic",
type: "delete",
async: false,
data: person,
dataType: "json",
success: function (data) {
alert('Submitted!');
},
error: function (result) {
alert('Oh no :(');
}
});
});
});
以下是summary.aspx / relic的代码
[WebMethod]
public string relic(person data)
{
dynamic result = data;
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["hey"].ConnectionString);
con.Open();
string query = "delete from "+data.name+" where ID= '"+data.surname+"'";
SqlCommand com = new SqlCommand(query, con);
com.ExecuteNonQuery();
con.Close();
return result;
}