当我在ajax块代码后面添加警告(文件)行时,但是当我删除警报(文件)代码时,代码就不工作了。
这工作很好:
function Delete(file) {
$.ajax({
type: "POST",
url: "Image.aspx/Delete",
data: '{file: "' + file + '" }',
contentType: "application/json; charset=utf-8",
datatype: "jsondata",
async: "true",
success: function (response) {
$("#statusBox").text("ok"); //alert(response.d);
},
error: function (response) {
$("#statusBox").text("error"+response.text);
// alert(response.status + ' ' + response.statusText);
},
complete: function () {
// $("#statusBox").text("completed");
}
});
alert(file);
}如果删除警告(文件)行代码web方法无效。
这是我的c# asp.net代码web方法:
[WebMethod]
public static string Delete(string file)
{
try
{
// int lastSlash=file.ind
// Lesson learnt - always check for a valid URI
if (Uri.IsWellFormedUriString(file, UriKind.Absolute))
{
Uri uri = new Uri(file);
file = (uri.LocalPath);
}
//file= file.Remove(0)
//File.Delete(file);
File.Delete(HttpContext.Current.Server.MapPath(@"~\" + file.Replace("/", @"\")));
}
catch (Exception ex)
{
return ex.Message;
}
return "ok";
}发布于 2014-11-28 13:22:02
您要异步发送请求,尝试制造假异步。有关更多信息,请查看this
发布于 2014-11-28 13:01:12
我在您的代码中看到了三个错误:
data: '{file: "' + file + '" }',
datatype: "jsondata",
async: "true",jsondata不是有效的数据类型。async是一个布尔值,而是分配一个字符串值。因此,这里的解决方案是:
data: {file: file }, // send a object
datatype: "text", // change to text because you are returning "ok" string
async: true, // remove the quotes 另一项建议是尝试使用默认标题:
contentType: "application/json; charset=utf-8",尝试删除这一行并查看。
https://stackoverflow.com/questions/27189126
复制相似问题