Uncaught SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (Asp.net MVC)
Uncaught SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (Asp.net MVC)
我正在使用 MVC 应用程序开发网站。我已使用 Ajax 删除特定记录。这里的问题是,删除功能在本地使用时工作正常。
几天前,我将 MVC 应用程序部署到 GoDaddy 服务器。当我在那里测试应用程序时,我发现使用 Ajax 删除功能无法正常工作。
这是脚本。当我调试时,我可以看到 id 值。
<script>
function DeleteCurrency(CourseId)
{
$.ajax({
url: "@Url.Action("Delete","Course")",
dataType: "json",
type: 'DELETE',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ 'id' : CourseId }),
async: true,
processData: false,
cache: false,
success: function (data) {
deleteCourse(CourseId);
},
error: function (xhr) {
alert('error');
}
});
}
function deleteCourse(row_id)
{
$("#" + row_id).remove();
toastr.error('Yes! You have successfully deleted!')
}
以及要删除的控制器操作代码。
[Authorize]
[HttpDelete]
public ActionResult Delete(int id)
{
try
{
CourseBl.Delete(id);
return Json("Deleted Successfully");
}
catch(Exception ex)
{
throw ex;
}
}
谁能帮我解决这个问题?
将您的 ajax 电话改为
$.ajax({
url: "@Url.Action("Delete","Course")?id=" + CourseId,
dataType: "json",
type: 'DELETE',
dataType: 'json',
cache: false,
success: function (data) {
deleteCourse(CourseId);
},
error: function (xhr) {
alert('error');
}
});
它应该可以工作。
如果没有,试试这个:
$.ajax({
url: "@Url.Action("Delete", "Course")",
type: 'Post',
data: {
id: CourseId,
},
cache: false,
dataType: 'json',
success: function (data) {
deleteCourse(CourseId);
},
error: function (jqXhr, textStatus, errorThrown) {
alert('error');
},
});
最后将您的操作方法更改为[HttpPost]
我正在使用 MVC 应用程序开发网站。我已使用 Ajax 删除特定记录。这里的问题是,删除功能在本地使用时工作正常。
几天前,我将 MVC 应用程序部署到 GoDaddy 服务器。当我在那里测试应用程序时,我发现使用 Ajax 删除功能无法正常工作。
这是脚本。当我调试时,我可以看到 id 值。
<script>
function DeleteCurrency(CourseId)
{
$.ajax({
url: "@Url.Action("Delete","Course")",
dataType: "json",
type: 'DELETE',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ 'id' : CourseId }),
async: true,
processData: false,
cache: false,
success: function (data) {
deleteCourse(CourseId);
},
error: function (xhr) {
alert('error');
}
});
}
function deleteCourse(row_id)
{
$("#" + row_id).remove();
toastr.error('Yes! You have successfully deleted!')
}
以及要删除的控制器操作代码。
[Authorize]
[HttpDelete]
public ActionResult Delete(int id)
{
try
{
CourseBl.Delete(id);
return Json("Deleted Successfully");
}
catch(Exception ex)
{
throw ex;
}
}
谁能帮我解决这个问题?
将您的 ajax 电话改为
$.ajax({
url: "@Url.Action("Delete","Course")?id=" + CourseId,
dataType: "json",
type: 'DELETE',
dataType: 'json',
cache: false,
success: function (data) {
deleteCourse(CourseId);
},
error: function (xhr) {
alert('error');
}
});
它应该可以工作。 如果没有,试试这个:
$.ajax({
url: "@Url.Action("Delete", "Course")",
type: 'Post',
data: {
id: CourseId,
},
cache: false,
dataType: 'json',
success: function (data) {
deleteCourse(CourseId);
},
error: function (jqXhr, textStatus, errorThrown) {
alert('error');
},
});
最后将您的操作方法更改为[HttpPost]