1

次の C#/jQuery で 500 を取得し続けます。特定の実装は正しくない可能性があり、それは大きな問題ではありません。私はハローワールドを立ち上げようとしています。C#に引数がない場合は機能しますが、データを受信しようとするとすぐに500が返されます.

[WebMethod]
public static string Test(string s)
{
    // never gets here
}

$.ajax({
    type: "POST",
    url: "ajax.aspx/" + method,
    /*async: true,*/
    data: "{data:'" + data + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        callback(data.d);
    }
});

最新の試みはこれであり、まだ機能しません:

[WebMethod()]
public static string Test(string data)
{
    // never gets here
    return "hello world";
}

$.ajax({
    type: "POST",
    url: "ajax.aspx/Test",
    data: "data: {data:'abc'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        alert("back");
    }
});
4

2 に答える 2

1

動作させるためにMVCを使用する必要はないと思います。json パラメータを渡す方法が間違っていると思います。以下のコードを確認して、動作するかどうかをお知らせください。

[WebMethod()]
public static string Test(string data)
{
  // never gets here
  return "hello world";
}

$.ajax({
    type: "POST",
    url: "ajax.aspx/Test",
    data:'{"data":"abc"}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
      alert(response);
    }
});
于 2012-07-30T07:08:52.610 に答える
0

これを試して

[HttpPost]
public ActionResult Test(string x)
{
    // never gets here
    return Json(true)
}

$.ajax({
    type: "Post",
    url: "ajax/Test",
    data: {x:'abc'},
    dataType: "json",
    success: function (data) {
       alert("back");
    }
});
于 2012-07-30T00:19:13.103 に答える