Ajax를 통해 C# 파일로 데이터를 보내고 싶지만 수신 된 데이터를 확인하면 null이됩니다. 내 코드에 문제가 있습니까?C# - Ajax 데이터 얻기
자바 스크립트 파일 데이터 (save.cshtml)를 수신
$(".save").click(function() {
var ss = "Helloo!";
$.ajax({
type: "POST",
url: "/Notes/save.cshtml",
global: true,
data: {fofo: ss},
processData: false,
contentType: false,
cache: false,
success: function(data){
console.log(data);
},
error: function (req, status, error) {
alert("There was a problem with the server. Try refreshing the page.");
return false;
}
});
});
C#을 파일
@{
var s = Request.Form["fofo"];
var result = "";
var userData = s;
var dataFile = Server.MapPath("~/Notes/lolo.txt");
File.WriteAllText(@dataFile, s);
result = "Information saved.";
}
@if(result != ""){
<p>Result: @result, @s</p>
}
이 한 형태이다? 그렇다면'.save'가 type = submit 인 경우 기본 제출을 막아야합니다. – charlietfl