无法从 Javascript 调用 Asp.net 方法
Failed to call Asp.net method from Javascript
我想从 Javascript 调用 Asp.Net 函数。我有一个调用 Asp.net MVC 函数的示例。
@{
var payUrl = "/recordings/recording-123.wav";
<!-- saves the wav file to local folder called recodings using a session value to make unique file names -->
}
function setupRecorder() {
Wami.setup({
id: "wami",
onReady: setupGUI
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: "wami",
recordUrl: "http://localhost:5296/home/Save",
playUrl: "@payUrl"
});
gui.setPlayEnabled(false);
}
这里是代码中的确切调用
recordUrl: "http://localhost:5296/home/Save",
HomeController 有一个在此处调用的方法 Save
public ActionResult Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-123.wav"), false);
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}
我想要 Asp.Net 中的确切内容,但我无法找到解决方案,如果有人可以帮助我,我将非常感谢你这是我项目中唯一剩下的部分,我只是需要保存音频。我这样做
<script>
function setupRecorder() {
Wami.setup({
id: "wami",
onReady: setupGUI
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: "wami",
recordUrl: "Default.aspx/Save",
playUrl: "/recordings/recording-123.wav"
});
gui.setPlayEnabled(false);
}
</script>
我有一个网络表单Default.aspx,它有方法保存
recordUrl: "Default.aspx/Save",
这是准确的 default.aspx.cs 方法。我试过 [HttpGet] 和 [httpPost] 都没有用。
[HttpGet]
[System.Web.Services.WebMethod]
public void Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-123.wav"), false);
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}
我认为您的保存方法需要标记为静态,因为它是一个网络方法。只有这样你才能从 JS
调用它
[System.Web.Services.WebMethod]
public static void Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-123.wav"), false);
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}
我想从 Javascript 调用 Asp.Net 函数。我有一个调用 Asp.net MVC 函数的示例。
@{
var payUrl = "/recordings/recording-123.wav";
<!-- saves the wav file to local folder called recodings using a session value to make unique file names -->
}
function setupRecorder() {
Wami.setup({
id: "wami",
onReady: setupGUI
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: "wami",
recordUrl: "http://localhost:5296/home/Save",
playUrl: "@payUrl"
});
gui.setPlayEnabled(false);
}
这里是代码中的确切调用
recordUrl: "http://localhost:5296/home/Save",
HomeController 有一个在此处调用的方法 Save
public ActionResult Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-123.wav"), false);
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}
我想要 Asp.Net 中的确切内容,但我无法找到解决方案,如果有人可以帮助我,我将非常感谢你这是我项目中唯一剩下的部分,我只是需要保存音频。我这样做
<script>
function setupRecorder() {
Wami.setup({
id: "wami",
onReady: setupGUI
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: "wami",
recordUrl: "Default.aspx/Save",
playUrl: "/recordings/recording-123.wav"
});
gui.setPlayEnabled(false);
}
</script>
我有一个网络表单Default.aspx,它有方法保存
recordUrl: "Default.aspx/Save",
这是准确的 default.aspx.cs 方法。我试过 [HttpGet] 和 [httpPost] 都没有用。
[HttpGet]
[System.Web.Services.WebMethod]
public void Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-123.wav"), false);
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}
我认为您的保存方法需要标记为静态,因为它是一个网络方法。只有这样你才能从 JS
调用它 [System.Web.Services.WebMethod]
public static void Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-123.wav"), false);
return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
}