Answer the question
In order to leave comments, you need to log in
Why is the view not loading after a POST request?
There is a controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View("Index");
}
public ActionResult PostInformation()
{
ViewBag.Text = Request["message"];
return View("Result");
}
}
function PostRequest() {
var xhttp = new XMLHttpRequest();
xhttp.open('POST', '/Home/PostInformation', true);
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.send("message=123123");
}
Answer the question
In order to leave comments, you need to log in
It is strange to give a full html markup for both a normal request and ajax, in the second case, you most likely need to give something else, in any case, the client does not process the response from the server.
If you want to give the full markup with a blocking request, then the usual form with method=post will do.
Ткните пальцем в строчку кода, которая обрабатывает результат AJAX-запроса ? Вы ткнули контроллер - он вернул ответ. Вопрос - куда вы дели ответ?
Допишите после send
if (xhttp.status != 200) {
// обработать ошибку
alert( xhttp.status + ': ' + xhttp.statusText ); // пример вывода: 404: Not Found
} else {
// вывести результат
alert( xhttp.responseText ); // responseText -- текст ответа.
}
и поставьте атрибут [HttpPost] методу PostInformation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question