だから私はWebMethod
(ASP .NET C#)にAJAXリクエストをしようとしています。問題を解決するために多くのトピックを見てきましたが、何も見つかりません。
これが私の現在のコードです:
<script type="text/javascript">
function mostrarMensaje() {
$.ajax({
type: "POST",
url: "index.aspx/devolverMensaje",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:
function (msg) {
alert('El mensaje devuelto por el servidor es: ' + msg);
},
error:
function (msg) {
alert(msg.status + " " + msg.statusText);
}
});
}
</script>
そして、それは私の WebMethod です:
namespace Test
{
public partial class Formulario_web1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod()]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static String devolverMensaje() {
return "pepe";
}
}
}
応答ステータスは 0 です。誰か助けてください。前もって感謝します!