在js中我试图使用post方法。这是MVC项目。
$.ajax({
type: 'POST',
url: '/Page/FileUpload',
data: formData,
contentType: false,
processData: false,
success: function(data) {
var result = JSON.parse(data);
var arrStr = result.Result.split(/[;]/);
if (result.Status !== 200) {
console.log("beklenmedik bir hata oluştu");
ui.hideDialog(self.$dialog);
self.$dialog.remove();
$("#mediatitle").val("");
$("#mediaurl").val("");
return;
}
if (arrStr[0] === "SUCCEED") {
var ext = $('#mediaurl').val().split(".").pop().toLowerCase();
if (ext == "pdf") {
node = '<div class="bs-callout bs-callout-info" style="padding: 20px; margin: -5px 0px 20px; border-width: 1px 1px 1px 5px; border-style: solid; border-color: rgb(238, 238, 238) rgb(238, 238, 238) rgb(238, 238, 238) rgb(27, 128, 158); border-image: initial; border-radius: 3px; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">' +
'<a href="#" class="tzobPdfViewer" data-page="' + arrStr[2] + '" data-category="file" data-guid="' + arrStr[1] + '"><h4 id="callout-progress-csp" style="font-weight: 500; color: rgb(27, 128, 158); margin-top: 0px; margin-bottom: 5px; font-size: 18px;">' + fileName + '</h4></a>' +
'</div></div>';
} else {
node = '<div class="bs-callout bs-callout-info" style="padding: 20px; margin: -5px 0px 20px; border-width: 1px 1px 1px 5px; border-style: solid; border-color: rgb(238, 238, 238) rgb(238, 238, 238) rgb(238, 238, 238) rgb(27, 128, 158); border-image: initial; border-radius: 3px; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">' +
'<a href="#" class="tzobFile" data-category="file" data-guid="' + arrStr[1] + '"><h4 id="callout-progress-csp" style="font-weight: 500; color: rgb(27, 128, 158); margin-top: 0px; margin-bottom: 5px; font-size: 18px;">' + fileName + '</h4></a>' +
'</div></div>';
}
var a = context.invoke('editor.pasteHTML', node);
ui.hideDialog(self.$dialog);
self.$dialog.remove();
$("#mediatitle").val("");
$("#mediaurl").val("");
} else {
if (arrStr[0] === "NO_FILE") {
console.log("beklenmedik bir hata oluştu");
ui.hideDialog(self.$dialog);
$("#mediatitle").val("");
$("#mediaurl").val("");
return;
}
}
},
error: function(error) {
console.log(error);
console.log("beklenmedik bir hata oluştu");
ui.hideDialog(self.$dialog);
self.$dialog.remove();
$("#mediatitle").val("");
$("#mediaurl").val();
return;
},
beforeSend: function() {
},
complete: function() {
}
});
上面的代码是发布数据,下面的代码是控制器。
public ActionResult FileUpload(Models.Media item) {
if (item == null ||
string.IsNullOrEmpty(item.Title) ||
string.IsNullOrEmpty(item.Category))
return Content(Serialization.JsonSerialize(new {
Status = 400
}));
//if (Request.Files.Count <= 0 && string.IsNullOrEmpty(item.Url))
// return Content(Serialization.JsonSerialize(new { Status = 401, Result = "NO_FILE" }));
return Content(Serialization.JsonSerialize(new {
Status = 200, Result = MediaRepository.AddFile(item)
}));
}
问题是它返回404错误。我无法解决问题。我该如何解决?