.net Mvc Ajax Post Error 403 Forbidden
I am doing a simple function to update a field in the database and I get this error: Failed to load resource: the server responded with a status of 403 (Forbidden) I do the reques
Solution 1:
Since you're sending a POST request, the parameters you need to send should not be a part of the URL. Try sending the parameters like:
request = $.ajax({
url: urlAction,
data: {id: id},
type: "POST",
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("It worked!");
},
error: function () {
alert("Error");
}
});
Further Reading: How to pass parameters in $ajax POST?
Solution 2:
request = $.ajax({
url: urlAction + '?id=' + id,
type: "get"
});
Substitute your code
var urlAction = "@Url.Action("UpdateLikeVisitBrandPhoto", "Report")";
It generates
/Report/UpdateLikeVisitBrandPhoto
To hit controller you need your url to be
/Controller/Action?param1=paramvalue //single param
/Controller/Action?param1=paramvalue ¶m2=paramvalue //multiple params,apppend each paramname with prefix &
Post a Comment for ".net Mvc Ajax Post Error 403 Forbidden"