Answer the question
In order to leave comments, you need to log in
ASP MVC 5. How to pass string to controller using POST method.?
AJAX:
var xml = "example";
function send(xml) { //отправка данных на сервер
$.ajax({
type: 'POST',
url: '/Home/Form',
data: xml,
success: function (responce) {
SaveToLocal("s",xml);// префикс s - sended
notification("Данные успешно отправлены", "success");
},
error: function (xhr, str) {
SaveToLocal("u",xml);// префикс u - unsended
notification("Подключение недоступно, данные сохранены в локальном хранилище","warning");
setTimeout(DelayResend, 30 * 1000);// функция отложенной отпраки с тайм аутом 30 сек.
}
})
};
[HttpPost]
public void Form(string xml)
{
string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
using (StreamWriter outputFile = new StreamWriter(mydocpath + @"\WriteLines.txt"))
outputFile.WriteLine(xml);
// return View();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question